---
title: "Hypertension Cascades"
author: "Jonas Prenissl"
date: "2/1/2019"
output: html_document
---


```{r Load Libraries and Input}
# Load libraries
library(tidyverse) 
library(dplyr) 
library(forcats) # for categorical variables (R for data science rec) --> see https://rdrr.io/cran/forcats/man/fct_unify.html
library(stringr) # for manipulating string variables (R for data science rec)
#library(lubridate) # for dates and times (R for data science rec)
#instalibrary(dummies) # to easily create dummies
library(ggplot2) 
library(ggrepel) # to avoid text labels in ggplot from overlapping
library(modelr) # to use "add_predictions()" for adding a column of predicted vals to your dataset
library(broom) # to create tidy data from model output
#library(margins) # R equivalent of Stata's margins command --> Thomas Leeper said this only to be used for marginal effects (not prediction)
#library(prediction) # Thomas Leeper's R package to get predicted probabilities
library(srvyr)  # survey package that also works with dplyr 
library(lmtest) # for likelihood ratio tests
#library(sandwich) # for robust standard errors 
#library(multiwayvcov) # for clustered standard errors
library(miceadds) # package to cluster SEs more easily than in multiwayvcov; it uses multiwayvcov, so the results between the two packages are exactly the same. 
library(speedglm)
library(foreign) # for importing non-csv datasets
library(readstata13) # foreign only reads Stata 12 or lower
#library(lme4) # for multi-level modeling
#library(lmerTest) # for p-values with the lmer command
#library(sjPlot) # for plotting lmer models
#library(texreg) # for tables
library(tableone) # Creates a table 1 (summary characteristics)
#library(mice) # md.pattern() function to see patterns of missing data 
#library(reshape) # to use the rescalar function

#library(car) # for easy attaching of new variables
#library(arm)
#library(mosaic)
#library(mosaicData)
library(mediation)  # for mediation analysis
#library(lattice)
#library(pander)
 library(rms)


#DHS.India.updated <- read.csv("~/Documents/Public Health Files/Public Health/public health/DHS with smoking and smokeless.csv")
#dhs <- DHS.India.updated
#dhs <- as_tibble(dhs)

DHS.with.smoking.and.smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension with screened/with changed prev/1 year weights/DHS with smoking and smokeless.csv")
dhs <- DHS.with.smoking.and.smokeless
dhs <- as_tibble(dhs)

setwd("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men")

##exclude 50-54 year old men

dhs <- filter(dhs,age<50)


###turn paradox responses into NA

dhs <- mutate(dhs,
                hypt = ifelse(hypt==1 & bp_ms==0, NA, hypt))
dhs <- mutate(dhs,
              hypt_med = ifelse(hypt_med==1 & bp_ms==0, NA, hypt_med))


###define hypertension based on positive answer for questionnaire questions AND BP measurement


dhs <-mutate(dhs,
             ex_htn_broad_ind = ifelse(is.na(ex_htn_narrow_ind)==T | is.na(hypt) ==T | is.na(hypt_med)==T, NA,ifelse(hypt_med==1 | hypt==1 | ex_htn_narrow_ind==1, 1, 0)))
 

###adapt weights for age and sex

dhs <- mutate(dhs, p_wt_new = ifelse(sex==0 & age==15, p_wt* { ( (25101) / (12159708) )   /   ( (3761) / (13739746) ) },
                                     ifelse(sex==0 & age==16,  p_wt* { ( (24702) / (11564358) )   /   ( (3844) / (13027935) ) },
                                            ifelse(sex==0 & age==17,  p_wt* { ( (22674) / (9868018) )   /   ( (3725) / (11349449) ) },
                                                   ifelse(sex==0 & age==18,   p_wt* { ( (25320) / (12937296) )   /   ( (4177) / (15020851) ) },
                                                          ifelse(sex==0 & age==19,   p_wt* { ( (19462) / (10014673) )   /   ( (3203) / (10844415) ) },
                                                                 ifelse(sex==0 & age==20,   p_wt* { ( (23573) / (13990570) )   /   ( (3632) / (14892165) ) },
                                                                        ifelse(sex==0 & age==21,  p_wt* { ( (18442) / (9446694) )   /   ( (3028) / (10532278) ) },
                                                                               ifelse(sex==0 & age==22,   p_wt* { ( (22212) / (11135249) )   /   ( (3472) / (12392976) ) },
                                                                                      ifelse(sex==0 & age==23,   p_wt* { ( (19660) / (9479866) )   /   ( (2989) / (9674189) ) },
                                                                                             ifelse(sex==0 & age==24,   p_wt* { ( (19262) / (9787150) )   /   ( (3061) / (10093085) ) },
                                                                                                    ifelse(sex==0 & age==25,  p_wt* { ( (25318) / (13456554) )   /   ( (3821) / (14311524) ) },
                                                                                                           ifelse(sex==0 & age==26,   p_wt* { ( (19390) / (9761967) )   /   ( (3131) / (10315030) ) },
                                                                                                                  ifelse(sex==0 & age==27,   p_wt* { ( (18113) / (8157318) )   /   ( (2957) / (8552032) ) },
                                                                                                                         ifelse(sex==0 & age==28,   p_wt* { ( (22299) / (11407090) )   /   ( (3413) / (10719926) ) },
                                                                                                                                ifelse(sex==0 & age==29,   p_wt* { ( (15413) / (7286828) )   /   ( (2476) / (7445696) ) },
                                                                                                                                       ifelse(sex==0 & age==30,  p_wt* { ( (27923) / (14770033) )   /   ( (4356) / (15628996) ) },
                                                                                                                                              ifelse(sex==0 & age==31,   p_wt* { ( 13757 / (6665743) )   /   ( (2190) / (7157502) ) },
                                                                                                                                                     ifelse(sex==0 & age==32, p_wt* { ( (20375) / (8812439) )   /   ( (3156) / (8801105) ) },
                                                                                                                                                            ifelse(sex==0 & age==33,  p_wt* { ( (14514) / (6655662) )   /   ( (2299) / (6108879) ) },
                                                                                                                                                                   ifelse(sex==0 & age==34,   p_wt* { ( (14285) / (7030400) )   /   ( (2348) / (6964192) ) },
                                                                                                                                                                          ifelse(sex==0 & age==35,   p_wt* { ( (27035) / (13385965) )   /   ( (4391) / (15036666) ) },
                                                                                                                                                                                 ifelse(sex==0 & age==36,   p_wt* { ( (15670) / (7760149) )   /   ( (2435) / (8067568) ) },
                                                                                                                                                                                        ifelse(sex==0 & age==37,   p_wt* { ( (13795) / (5907352) )   /   ( (2176) / (5784879) ) },
                                                                                                                                                                                               ifelse(sex==0 & age==38,   p_wt* { ( (18693) / (9381357) )   /   ( (2723) / (8090401) ) },
                                                                                                                                                                                                      ifelse(sex==0 & age==39,   p_wt* { ( (12683) / (5786480) )   /   ( (1968) / (5939867) ) },
                                                                                                                                                                                                             ifelse(sex==0 & age==40,   p_wt* { ( (25682) / (13355581) )   /   ( (3974) / (15173411) ) },
                                                                                                                                                                                                                    ifelse(sex==0 & age==41,  p_wt* { ( (11046) / (5395597) )   /   ( (1819) / (6172297) ) },
                                                                                                                                                                                                                           ifelse(sex==0 & age==42,  p_wt* { ( (16124) / (6523816) )   /   ( (2544) / (6856826) ) },
                                                                                                                                                                                                                                  ifelse(sex==0 & age==43,   p_wt* { ( (11983) / (4865438) )   /   ( (1797) / (4468914) ) },
                                                                                                                                                                                                                                         ifelse(sex==0 & age==44,   p_wt* { ( (10836) / (4752294) )   /   ( (1714) / (4873938) ) },
                                                                                                                                                                                                                                                ifelse(sex==0 & age==45,  p_wt* { ( (23877) / (11187786) )   /   ( (3854) / (12685175) ) },
                                                                                                                                                                                                                                                       ifelse(sex==0 & age==46,  p_wt* { ( (11752) / (5257138) )   /   ( (1895) / (5735540) ) },
                                                                                                                                                                                                                                                              ifelse(sex==0 & age==47,   p_wt* { ( (11295) / (3908175) )   /   ( (1714) / (4043122) ) },
                                                                                                                                                                                                                                                                     ifelse(sex==0 & age==48, p_wt* { ( (14786) / (6081038) )   /   ( (2119) / (5568554) ) },
                                                                                                                                                                                                                                                                            ifelse(sex==0 & age==49,   p_wt* { ( (10399) / (3746076) )   /   ( (1506) / (4105723)) }, p_wt ))))))))))))))))))))))))))))))))))))
dhs <- mutate(dhs, p_wt_new = ifelse(sex==0 & age>=50, p_wt_new/1.013194, p_wt_new )) 
dhs <- mutate(dhs, p_wt_new = ifelse(sex==0 & age>=50, p_wt * { ((6.72342) * (1.013194)) / (0.998047) }, p_wt_new ))   



# Filter out those that are pregnant  ###

dhs <- dplyr::filter(dhs, pregnant == 0)  # only keep those who aren't pregnant (they didn't measure glucose in pregnant women anyway); dhs_nomiss has no missings in the pregnant variable

###filter out those with missing cascade parameters

dhs_nomiss <- dplyr::filter(dhs, is.na(dhs$ex_htn_narrow_ind) == F & is.na(dhs$hypt) == F & is.na(dhs$hypt_med) == F & is.na(dhs$bp_ms) == F)


##Doublechecks
sum(is.na(dhs$ex_htn_narrow_ind)==T)
sum(is.na(dhs$ex_htn_broad_ind)==T)
sum(is.na(dhs$hypt)==T)
sum(is.na(dhs$hypt_med)==T)

sum(is.na(dhs_nomiss$ex_htn_narrow_ind)==T) 
sum(is.na(dhs_nomiss$ex_htn_broad_ind)==T) 
sum(is.na(dhs_nomiss$hypt)==T)
sum(is.na(dhs_nomiss$hypt_med)==T)
sum(is.na(dhs_nomiss$dbp_avg)==T)
sum(is.na(dhs$dbp_avg)==T)
sum(is.na(dhs_nomiss$sbp_avg)==T)

summary(dhs$dbp3)
hist(dhs$dbp3)

summary(dhs$sbp_avg)
hist(dhs$sbp_avg)

summary(dhs$dbp_avg)
hist(dhs$dbp_avg)






##check definitions

dhs_nomiss$ex_htn_narrow_ind <- as.factor(dhs_nomiss$ex_htn_narrow_ind)
dhs_nomiss$ex_htn_broad_ind <- as.factor(dhs_nomiss$ex_htn_broad_ind)
dhs_nomiss$hypt <- as.factor(dhs_nomiss$hypt)
dhs_nomiss$hypt_med <- as.factor(dhs_nomiss$hypt_med)


dhs$ex_htn_narrow_ind <- as.factor(dhs$ex_htn_narrow_ind)
dhs$ex_htn_broad_ind <- as.factor(dhs$ex_htn_broad_ind)
dhs$hypt <- as.factor(dhs$hypt)
dhs$hypt_med <- as.factor(dhs$hypt_med)


summary(dhs_nomiss$ex_htn_broad_ind)
summary(dhs_nomiss$ex_htn_narrow_ind)
summary(dhs_nomiss$hypt)
summary(dhs_nomiss$hypt_med)
summary(dhs_nomiss$ex_htn_broad_ind)



#works missing weights as average

dhs_nomiss <- mutate(dhs_nomiss, 
              p_wt = ifelse(is.na(p_wt)==TRUE, mean(p_wt, na.rm=TRUE), p_wt))

dhs_nomiss <- dplyr::mutate(dhs_nomiss, 
                     p_wtfemale = ifelse(sex==1, dhs_nomiss$p_wt, NA))

dhs_nomiss <- dplyr::mutate(dhs_nomiss, 
                     p_wtmale = ifelse(sex==0, dhs_nomiss$p_wt, NA))



# 9. Create age group women and men, educat group in dhs ##

dhs <- dplyr::mutate(dhs, age_grp = ifelse(age<=24, "15-24", 
                                                 ifelse(age>24 & age<=34, "25-34",
                                                        ifelse(age>34 & age<=44, "35-44",
                                                               ifelse(age>44 & age<=49, "45-49","50-54"))))) 
dhs$age_grp <- factor(dhs$age_grp, levels = c("15-24", "25-34", "35-44", "45-49", "50-54"))
dhs <- within(dhs, age_grp <- relevel(age_grp, ref = "15-24"))




dhs <- dplyr::mutate(dhs, age_grp_women = ifelse(age<=24 & sex==1, "15-24", 
                                                               ifelse(age>24 & sex==1 & age<=34, "25-34",
                                                                      ifelse(age>34 & sex==1 & age<=44, "35-44",
                                                                             ifelse(age>44 & sex==1 & age<=49, "45-49",">49"))))) 
dhs$age_grp_women <- factor(dhs$age_grp_women, levels = c("15-24", "25-34", "35-44", "45-49", ">49"))
dhs <- within(dhs, age_grp_women <- relevel(age_grp_women, ref = "15-24"))


dhs <- dplyr::mutate(dhs, age_grp_men = ifelse(age<=24 & sex==0, "15-24", 
                                                             ifelse(age>24 & sex==0 & age<=34, "25-34",
                                                                    ifelse(age>34 & sex==0 & age<=44, "35-44",
                                                                           ifelse(age>44 & sex==0 & age<=54, "45-54", ">54"))))) 
dhs$age_grp_men <- factor(dhs$age_grp_men, levels = c("15-24", "25-34", "35-44", "45-54", ">54"))
dhs <- within(dhs, age_grp_men <- relevel(age_grp_men, ref = "15-24"))



dhs <- dplyr::mutate(dhs, educatnames = ifelse(educat==0, "No formal schooling", 
                                                             ifelse(educat==1, "Primary school unfinished",
                                                                    ifelse(educat==2, "Primary school finished",
                                                                           ifelse(educat==3, "High school unfinished",
                                                                                  ifelse(educat==4, "High school or above", "Refused")))))) 
dhs$educatnames <- factor(dhs$educatnames, levels = c("No formal schooling", "Primary school unfinished", "Primary school finished", "High school unfinished", "High school or above", "Refused"))
dhs <- within(dhs, educatnames<- relevel(educatnames, ref = "No formal schooling"))


dhs <- dplyr::mutate(dhs, maritalnames = ifelse(marital==1, "Never married", 
                                                              ifelse(marital==2, "Currently married",
                                                                     ifelse(marital==3, "Separated",
                                                                            ifelse(marital==4, "Divorced",
                                                                                   ifelse(marital==5, "Widowed",
                                                                                          ifelse(marital==6, "Cohabitating",
                                                                                                 ifelse(marital==7, "divorced or separated or deserted or widowed","Refused")))))))) 
dhs$maritalnames <- factor(dhs$maritalnames, levels = c("Never married", "Currently married", "Separated", "Divorced", "Widowed", "Cohabitating", "divorced/separated/deserted/widowed", "Refused"))
dhs <- within(dhs, maritalnames<- relevel(maritalnames, ref = "Never married"))

###create married variable in dhs


dhs <- mutate( dhs,
                      married = ifelse( dhs$marital==2, 1, 0))

dhs$married <- as.factor(dhs$married)


dhs <- mutate( dhs,
                      marriednames = ifelse( dhs$marital==2, "Married","Not married"))

dhs$marriednames <- as.factor(dhs$marriednames)

dhs <- within(dhs, marriednames<- relevel(marriednames, ref = "Not married"))



###create age_grp2 in dhs

dhs <- mutate(dhs,
                     age_grp2 = 
                       as.factor(ifelse(
                         age>=15 & age<20, "15-19",
                         ifelse(age>=20 & age<25, "20-24",
                                ifelse(age>=25 & age<30, "25-29",
                                       ifelse(age>=30 & age<35,"30-34", 
                                          ifelse(age>=35 & age<40, "35-39",
                                              ifelse(age>=40 & age<45, "40-44",
                                                     ifelse(age>=45 & age<50, "45-49",
                                                            ifelse(age>=50 & age<55, "50-54","54+"))))))))))



######wealth_quintile_rurb as factor in dhs

dhs$wealth_quintile_rurb <- as.factor(dhs$wealth_quintile_rurb)


###bmi group
dhs <- mutate(dhs,
                     bmi_group = ifelse(bmi<18.5, "<18.5kg/m2",
                                        ifelse(bmi>=18.5 & bmi<23, "18.5-22.9 kg/m2",
                                               ifelse(bmi>=23 & bmi<25, "23.0-24.9 kg/m2",
                                                      ifelse(bmi>=25 & bmi<27.5, "25.0-27.4 kg/m2",
                                                             ifelse(bmi>=27.5 & bmi<30, "27.5-29.9 kg/m2",
                                                                    ifelse(bmi>=30, ">= 30.0 kg/m2", NA)))))))


dhs$bmi_group <- factor(dhs$bmi_group, levels = c("<18.5kg/m2", "18.5-22.9 kg/m2", "23.0-24.9 kg/m2", "25.0-27.4 kg/m2", "27.5-29.9 kg/m2", ">= 30.0 kg/m2"))
dhs <- within(dhs, bmi_group<- relevel(bmi_group, ref = "18.5-22.9 kg/m2"))



################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India in dhs
dhs <- mutate(dhs, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))



# create labels for female, rural, rich in dhs

dhs <- mutate(dhs, 
                     rural = ifelse(urban==1, 0, 1),
                     female = ifelse(sex==1, 1, 0),
                     male = ifelse(sex==1, 0, 1))
dhs$rural <- as.factor(dhs$rural)
dhs$female <- as.factor(dhs$female)
dhs$male <- as.factor(dhs$male)


#make factors


dhs <- dhs %>% 
  mutate(female_lab = as.factor(ifelse(is.na(female) == TRUE, NA, 
                                       ifelse(female == 1, "Female", "Male"))),
         urban_lab = as.factor(ifelse(is.na(rural) == TRUE, NA, 
                                      ifelse(rural == 1, "Rural", "Urban"))),
         wealth_quintile_rurb_lab = as.factor(ifelse(is.na(wealth_quintile_rurb) == TRUE, NA, 
                                                     ifelse( wealth_quintile_rurb == 1, "Q1 (Poorest)", 
                                                             ifelse(wealth_quintile_rurb == 2, "Q2",
                                                                    ifelse(wealth_quintile_rurb == 3, "Q3",
                                                                           ifelse(wealth_quintile_rurb == 4, "Q4",
                                                                                  ifelse(wealth_quintile_rurb == 5, "Q5 (Richest)", NA))))))))

dhs$wealth_quintile_rurb_lab <- as.factor(dhs$wealth_quintile_rurb_lab)
dhs<- within(dhs, wealth_quintile_rurb_lab <- relevel(wealth_quintile_rurb_lab, ref = "Q1 (Poorest)"))




# 9. Create age group women and men, educat group in dhs_nomiss #

###create married variable

dhs_nomiss <- mutate( dhs_nomiss,
                      marriednames = ifelse( dhs_nomiss$marital==2, "Married","Not married"))
###Age groups


dhs_nomiss <- dplyr::mutate(dhs_nomiss, age_grp = ifelse(age<=24, "15-24", 
                                                         ifelse(age>24 & age<=34, "25-34",
                                                                ifelse(age>34 & age<=44, "35-44","45-49")))) 
dhs_nomiss$age_grp <- factor(dhs_nomiss$age_grp, levels = c("15-24", "25-34", "35-44", "45-49"))
dhs_nomiss <- within(dhs_nomiss, age_grp <- relevel(age_grp, ref = "15-24"))



dhs_nomiss <- dplyr::mutate(dhs_nomiss, age_grp_women = ifelse(age<=24 & sex==1, "15-24", 
                                                 ifelse(age>24 & sex==1 & age<=34, "25-34",
                                                        ifelse(age>34 & sex==1 & age<=44, "35-44",
                                                               ifelse(age>44 & sex==1 & age<=49, "45-49",">49"))))) 
dhs_nomiss$age_grp_women <- factor(dhs_nomiss$age_grp_women, levels = c("15-24", "25-34", "35-44", "45-49", ">49"))
dhs_nomiss <- within(dhs_nomiss, age_grp_women <- relevel(age_grp_women, ref = "15-24"))


dhs_nomiss <- dplyr::mutate(dhs_nomiss, age_grp_men = ifelse(age<=24 & sex==0, "15-24", 
                                               ifelse(age>24 & sex==0 & age<=34, "25-34",
                                                      ifelse(age>34 & sex==0 & age<=44, "35-44",
                                                             ifelse(age>44 & sex==0 & age<=54, "45-54", ">54"))))) 
dhs_nomiss$age_grp_men <- factor(dhs_nomiss$age_grp_men, levels = c("15-24", "25-34", "35-44", "45-54", ">54"))
dhs_nomiss <- within(dhs_nomiss, age_grp_men <- relevel(age_grp_men, ref = "15-24"))


###age group for educat analysis

dhs_nomiss <- dplyr::mutate(dhs_nomiss, age_grp_educat = ifelse(age>18 & age<=26, "19-26", 
                                                                ifelse(age>26 & age<=34, "27-34",
                                                                       ifelse(age>34 & age<=42, "35-42",
                                                                              ifelse(age>42 & age<=49, "43-49", NA))))) 
dhs_nomiss$age_grp_educat <- factor(dhs_nomiss$age_grp_educat, levels = c("19-26", "27-34", "35-42", "43-49"))
dhs_nomiss <- within(dhs_nomiss, age_grp_educat <- relevel(age_grp_educat, ref = "19-26"))

dhs_nomiss <- dplyr::mutate(dhs_nomiss, age_grp_educat_men =  ifelse(age>18 & age<=26, "19-26", 
                                                                     ifelse(age>26 & age<=34, "27-34",
                                                                            ifelse(age>34 & age<=42, "35-42",
                                                                                   ifelse(age>42 , "43-54", NA))))) 
dhs_nomiss$age_grp_educat_men <- factor(dhs_nomiss$age_grp_educat_men, levels = c("19-26", "27-34", "35-42", "43-54"))
dhs_nomiss <- within(dhs_nomiss, age_grp_educat_men <- relevel(age_grp_educat_men, ref = "19-26"))



####educat reform


dhs_nomiss <- dplyr::mutate(dhs_nomiss, educat = ifelse(educat==1 | educat==0 , 0, educat))

dhs_nomiss <- dplyr::mutate(dhs_nomiss, educatnames = 
                              ifelse( educat==0, "Primary school unfinished",
                                      ifelse(educat==2, "Primary school finished",
                                             ifelse(educat==3, "Secondary school unfinished",
                                                    ifelse(educat==4, "Secondary school or above", "Refused"))))) 
dhs_nomiss$educatnames <- factor(dhs_nomiss$educatnames, levels = c( "Primary school unfinished", "Primary school finished", "Secondary school unfinished", "Secondary school or above", "Refused"))
dhs_nomiss <- within(dhs_nomiss, educatnames<- relevel(educatnames, ref = "Primary school unfinished"))



dhs_nomiss <- dplyr::mutate(dhs_nomiss, maritalnames = ifelse(marital==1, "Never married", 
                                                ifelse(marital==2, "Currently married",
                                                       ifelse(marital==3, "Separated",
                                                              ifelse(marital==4, "Divorced",
                                                                     ifelse(marital==5, "Widowed",
                                                                            ifelse(marital==6, "Cohabitating",
                                                                                   ifelse(marital==7, "divorced or separated or deserted or widowed","Refused")))))))) 


dhs_nomiss$maritalnames <- factor(dhs_nomiss$maritalnames, levels = c("Never married", "Currently married", "Separated", "Divorced", "Widowed", "Cohabitating", "divorced/separated/deserted/widowed", "Refused"))
dhs_nomiss <- within(dhs_nomiss, maritalnames<- relevel(maritalnames, ref = "Never married"))




###create married variable

dhs_nomiss <- mutate( dhs_nomiss,
                      married = ifelse( dhs_nomiss$marital==2, 1, 0))

dhs_nomiss$married <- as.factor(dhs_nomiss$married)


dhs_nomiss <- mutate( dhs_nomiss,
                      marriednames = ifelse( dhs_nomiss$married==1, "Married","Not married"))

dhs_nomiss$marriednames <- as.factor(dhs_nomiss$marriednames)

dhs_nomiss <- within(dhs_nomiss, marriednames<- relevel(marriednames, ref = "Not married"))

###create age_grp2

dhs_nomiss <- mutate(dhs_nomiss,
              age_grp2 = 
                as.factor(ifelse(
                  age>=15 & age<20, "15-19",
                  ifelse(age>=20 & age<25, "20-24",
                         ifelse(age>=25 & age<30, "25-29",
                                ifelse(age>=30 & age<35,"30-34", 
                                       ifelse(age>=35 & age<40, "35-39",
                                              ifelse(age>=40 & age<45, "40-44",
                                                     ifelse(age>=45 & age<50, "45-49",
                                                            ifelse(age>=50 & age<55, "50-54","54+"))))))))))

dhs_nomiss <- mutate(dhs_nomiss,
                     age_grpOR = 
                       as.factor(ifelse(
                         age>=15 & age<20, "15-19",
                         ifelse(age>=20 & age<25, "20-24",
                                ifelse(age>=25 & age<30, "25-29",
                                       ifelse(age>=30 & age<35,"30-34", 
                                              ifelse(age>=35 & age<40, "35-39",
                                                     ifelse(age>=40 & age<45, "40-44",
                                                            ifelse(age>=45 & age<50, "45-49",
                                                                   ifelse(age>=50 & age<55, "50-54",NA))))))))))

dhs_nomiss$age_grpOR <- factor(dhs_nomiss$age_grpOR, levels = c("15-19","20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54"))

dhs_nomiss <- within(dhs_nomiss, age_grpOR <- relevel(age_grpOR, ref = "15-19"))


dhs_nomiss <- mutate(dhs_nomiss,
                     state = dhs_nomiss$ex_state_ind)

dhs_nomiss$state  <- as.factor(dhs_nomiss$state)



### test if unique and number
#unique(dhs$d_id)
#length(unique(dhs$d_id))
#length(unique(dhs$psu))


#####Create BMI Groups for heatmaps

dhs_nomiss <- mutate(dhs_nomiss,
                     bmi_group = ifelse(bmi<18.5, "<18.5kg/m2",
                                        ifelse(bmi>=18.5 & bmi<23, "18.5-22.9 kg/m2",
                                               ifelse(bmi>=23 & bmi<25, "23.0-24.9 kg/m2",
                                                      ifelse(bmi>=25 & bmi<27.5, "25.0-27.4 kg/m2",
                                                             ifelse(bmi>=27.5 & bmi<30, "27.5-29.9 kg/m2",
                                                                    ifelse(bmi>=30, "\u2265 30.0 kg/m2", NA)))))))


dhs_nomiss$bmi_group <- factor(dhs_nomiss$bmi_group, levels = c("<18.5kg/m2", "18.5-22.9 kg/m2", "23.0-24.9 kg/m2", "25.0-27.4 kg/m2", "27.5-29.9 kg/m2", "\u2265 30.0 kg/m2"))
dhs_nomiss <- within(dhs_nomiss, bmi_group<- relevel(bmi_group, ref = "18.5-22.9 kg/m2"))



dhs_nomiss <- mutate(dhs_nomiss,
                     bmi_group_large = ifelse(bmi<18.5, "<18.5kg/m2",
                                        ifelse(bmi>=18.5 & bmi<25, "18.5-24.9 kg/m2",
                                               ifelse(bmi>=25 & bmi<30, "25.0-29.9 kg/m2",
                                                                    ifelse(bmi>=30, "\u2265 30.0 kg/m2", NA)))))

dhs_nomiss$bmi_group_large <- factor(dhs_nomiss$bmi_group_large, levels = c("<18.5kg/m2", "18.5-24.9 kg/m2", "25.0-29.9 kg/m2", "\u2265 30.0 kg/m2"))
dhs_nomiss <- within(dhs_nomiss, bmi_group_large<- relevel(bmi_group_large, ref = "<18.5kg/m2"))



                     
# htn medication as factor

dhs_nomiss$hypt_med <- as.factor(dhs_nomiss$hypt_med)

######wealth_quintile_rurb as factor

dhs_nomiss$wealth_quintile_rurb <- as.factor(dhs_nomiss$wealth_quintile_rurb)


# create labels for female, rural, rich

dhs_nomiss <- mutate(dhs_nomiss, 
              rural = ifelse(urban==1, 0, 1),
              female = ifelse(sex==1, 1, 0),
              male = ifelse(sex==1, 0, 1))
dhs_nomiss$rural <- as.factor(dhs_nomiss$rural)
dhs_nomiss$female <- as.factor(dhs_nomiss$female)
dhs_nomiss$male <- as.factor(dhs_nomiss$male)



dhs_nomiss <- dhs_nomiss %>% 
  mutate(female_lab = as.factor(ifelse(is.na(female) == TRUE, NA, 
                                       ifelse(female == 1, "Female", "Male"))),
         urban_lab = as.factor(ifelse(is.na(rural) == TRUE, NA, 
                                      ifelse(rural == 1, "Rural", "Urban"))),
         wealth_quintile_rurb_lab = as.factor(ifelse(is.na(wealth_quintile_rurb) == TRUE, NA, 
                                                     ifelse( wealth_quintile_rurb == 1, "Q1 (Poorest)", 
                                                             ifelse(wealth_quintile_rurb == 2, "Q2",
                                                             ifelse(wealth_quintile_rurb == 3, "Q3",
                                                                    ifelse(wealth_quintile_rurb == 4, "Q4",
                                                             ifelse(wealth_quintile_rurb == 5, "Q5 (Richest)", NA))))))))

dhs_nomiss$wealth_quintile_rurb_lab <- as.factor(dhs_nomiss$wealth_quintile_rurb_lab)
dhs_nomiss<- within(dhs_nomiss, wealth_quintile_rurb_lab <- relevel(wealth_quintile_rurb_lab, ref = "Q1 (Poorest)"))



## create missing htn VARIABLE summary, summary dhs


#dhs <- mutate(dhs, 
#              missing_htn = ifelse(is.na(ex_htn_broad_ind)==T, 1, 0))
#dhs <- mutate(dhs, 
#              missing_htn_names = ifelse(missing_htn==1, "Missing Hypertension Value", "Has Hypertension Value"))

#table_missing_htn_names <- c( "ex_htn_broad_ind", "age_grp", 
#                 "age_grp_men", "age_grp_women", "educatnames", "wealth_quintile_rurb_lab", "maritalnames", "missing_htn_names", "urban_lab")




#stratbymissinghtn <- CreateTableOne(vars = table_missing_htn_names, data=dhs, strata=c("missing_htn_names"), includeNA=T)
#print(stratbymissinghtn)


###create missing htn MEASUREMENT summary


#dhs_only_missing <- dplyr::filter(dhs, is.na(dhs$ex_htn_narrow_ind) == T | is.na(dhs$hypt) == T | is.na(dhs$hypt_med) == T | is.na(dhs$bp_ms) == T)

#dhs <- mutate(dhs, 
#              missing_htn_measure_names = ifelse(missing_htn_measure==1, "missing hypertension measurement", "existing hypertension measurement"))

#table_missing_htn_measure_names <- c("female_lab", 
#                         "ex_htn_narrow_ind", "age_grp", 
 #                        "age_grp_men", "age_grp_women", "educatnames", "wealth_quintile_rurb_lab", "marriednames", "missing_htn_measure_names", "urban_lab")




#stratbymissinghtnmeasure <- CreateTableOne(vars = table_missing_htn_measure_names, data=dhs, strata=c("missing_htn_measure_names"), includeNA=T)
#missing <-print(stratbymissinghtnmeasure)

#write.csv(missing, file="missing htn 03.4.18.csv")

#stratbysexhtn <- CreateTableOne(vars = table_missing_htn_measure_names, data=dhs, strata=c("female_lab"), includeNA=T)
#print(stratbysexhtn)


# Summary dhs_nomiss

dhs_nomiss$ex_htn_broad_ind <- as.factor(dhs_nomiss$ex_htn_broad_ind)

dhs_nomiss$tobacco_smokeless <- as.factor(dhs_nomiss$tobacco_smokeless)
dhs_nomiss$tobacco_smoked <- as.factor(dhs_nomiss$tobacco_smoked)


table1names <- c("ex_htn_broad_ind", "age_grpOR",
                 "age_grp_men", "age_grp_women", "educatnames", "wealth_quintile_rurb_lab", "marriednames", "urban_lab","bmi_group", "tobacco_smoked", "tobacco_smokeless")
"missing")



totalwithmiss <- CreateTableOne(vars = table1names, data=dhs_nomiss, includeNA=T)
total <- print(totalwithmiss)

write.csv(total, file="dhs_nomiss summary.csv")

sexwithmiss <- CreateTableOne(vars = table1names, data=dhs_nomiss, strata=c("female_lab"), includeNA=T)
sexdhs_nomiss <- print(sexwithmiss)

write.csv(sexdhs_nomiss, file= "dhs_nomiss summary per sex.csv")



# Summary dhs

sum(is.na(dhs$fbg))
sum(is.na(dhs$hypt))
sum(is.na(dhs$sex))

table1names <- c("ex_htn_broad_ind", "age_grp",
                 "age_grp_men", "age_grp_women", "educatnames", "wealth_quintile_rurb_lab", "marriednames", "urban_lab")
"missing")



totalwithmiss <- CreateTableOne(vars = table1names, data=dhs, includeNA=T)
total <- print(totalwithmiss)

write.csv(total, file="dhs summary.csv")


sexwithmiss <- CreateTableOne(vars = table1names, data=dhs, strata=c("female_lab"), includeNA=T)
total<-print(sexwithmiss)

write.csv(total, file="dhs summary by sex.csv")

#ex_htn_broad_indwithmiss <- CreateTableOne(vars = table1names, data=dhs_nomiss, strata=c("ex_htn_broad_ind"), includeNA=T)
#print(ex_htn_broad_indwithmiss)




# create stratum ID
dhs_nomiss$state_dist_str <- as.character(dhs_nomiss$ex_state_ind)
dhs_nomiss$rural_str <- as.character(dhs_nomiss$rural)
dhs_nomiss <- mutate(dhs_nomiss, 
              stratumid = str_c(state_dist_str, rural_str, sep = "_")) 
dhs_nomiss$stratumid <- as.factor(dhs_nomiss$stratumid)










##htn as numeric

dhs_nomiss <- mutate(dhs_nomiss,
              ex_htn_broad_ind_dbl = as.numeric(dhs_nomiss$ex_htn_broad_ind)-1)


####Check mean, median, 25th, 75th, min and max  in 1) a district, and 2) a PSU, if ex_htn_narrow_ind !=NA 

####check districts



#uniquestates<-unique(dhs_nomiss$ex_state_ind)

#keeptrack4<-NULL

#for(state in (uniquestates)){
 
#  keeptrack4<-c(keeptrack4,sum(dhs_nomiss$ex_state_ind==state))
#}
#names(keeptrack4)<-uniquestates
#summary(keeptrack4)

####check psus


#uniquepsu<-unique(dhs_nomiss_noNAinpsu$psu)

#keeptrack4<-NULL

#for(dis in (uniquepsu)){
  
  #keeptrack4<-c(keeptrack4,sum(dhs_nomiss_noNAinpsu$psu==dis))
#}
#names(keeptrack4)<-uniquepsu
#summary(keeptrack4)


########################  CREATE HTN Subgroups  #################################################

#filter htn only
dhs_nomiss_htn_only <- filter(dhs_nomiss, (ex_htn_broad_ind)==1) 


##screened htn

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                     htn_screened = bp_ms)

dhs_nomiss_htn_only$htn_screened <- as.factor(dhs_nomiss_htn_only$htn_screened)

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                              
                              htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss_htn_only$htn_screened)


##aware htn



## Test if there are paradoxically treated but unaware patients
dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                     treated_and_unaware = ifelse( hypt==0 &hypt_med==1, 1, 0))
dhs_nomiss_htn_only$treated_and_unaware <- as.factor(dhs_nomiss_htn_only$treated_and_unaware)
summary(dhs_nomiss_htn_only$treated_and_unaware)

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                             treated_and_unaware = ifelse( htn_aware==0 &htn_treated==1, 1, 0))
dhs_nomiss_htn_only$treated_and_unaware <- as.factor(dhs_nomiss_htn_only$treated_and_unaware)
summary(dhs_nomiss_htn_only$treated_and_unaware)

##aware htn as subset of htn



dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                     htn_aware = ifelse(hypt==1 | hypt_med==1, 1, 0))


dhs_nomiss_htn_only$htn_aware <- as.factor(dhs_nomiss_htn_only$htn_aware)



dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss_htn_only$htn_aware)

##treated htn as subset of htns


dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                                   htn_treated = ifelse(hypt_med==1, 1, 0))
#dhs_nomiss_htn_only[which(is.na(dhs_nomiss_htn_only$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss_htn_only$htn_treated <- as.factor(dhs_nomiss_htn_only$htn_treated)

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                                   
                                   htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss_htn_only$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                                             htn_controlled = ifelse((hypt_med==1 & ex_htn_narrow_ind==0), 1, 0))

dhs_nomiss_htn_only$htn_controlled <- as.factor(dhs_nomiss_htn_only$htn_controlled)

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                                             
                                             htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss_htn_only$htn_controlled)


###paradoxically aware but unscreened

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                              aware_and_unscreened = ifelse( htn_aware==1 & htn_screened==0, 1, 0))
dhs_nomiss_htn_only$aware_and_unscreened <- as.factor(dhs_nomiss_htn_only$aware_and_unscreened)
summary(dhs_nomiss_htn_only$aware_and_unscreened)


###paradoxically treated and unscreened

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                              treated_and_unscreened = ifelse( htn_treated==1 & htn_screened==0, 1, 0))
dhs_nomiss_htn_only$treated_and_unscreened <- as.factor(dhs_nomiss_htn_only$treated_and_unscreened)
summary(dhs_nomiss_htn_only$treated_and_unscreened)

## Test if there are paradoxically treated but unaware patients
dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                     treated_and_unaware = ifelse( htn_aware==0 & htn_treated==1, 1, 0))
dhs_nomiss_htn_only$treated_and_unaware <- as.factor(dhs_nomiss_htn_only$treated_and_unaware)
summary(dhs_nomiss_htn_only$treated_and_unaware)


###create Barchart variables with separate subsets#


##get aware htn

table6names <- c( "hypt", "hypt_med") ## hypt=0 are aware htns


totalwithmiss <- CreateTableOne(vars = table6names, data=dhs_nomiss_htn_only, includeNA=T)
print(totalwithmiss)


#filter htn,aware

dhs_nomiss_htn_and_aware_only <- filter(dhs_nomiss_htn_only, htn_aware==1)

#get treated htns of aware htns

table7names <- c("htn_treated") ###hypt_med are treated htns


totalwithmiss <- CreateTableOne(vars = table7names, data=dhs_nomiss_htn_and_aware_only, includeNA=T)
print(totalwithmiss)

#filter htn,aware,treated
dhs_nomiss_htn_and_treated_only  <- filter(dhs_nomiss_htn_only, htn_treated==1)

#get controlled of htn,aware,treated

table8names <- c("ex_htn_narrow_ind" ) ####ex_htn_narrow_ind==0 are controlled htns


totalwithmiss <- CreateTableOne(vars = table8names, data=dhs_nomiss_htn_and_treated_only, includeNA=T)
print(totalwithmiss)


####create htn, controlled htn, treated htn and unknowing htn as subsets

#create htn as numeric
dhs_nomiss <- mutate(dhs_nomiss,
                     ex_htn_broad_ind = as.numeric(dhs_nomiss$ex_htn_broad_ind)-1)



####Create PSUS for subsets besides dhs, always if working with psu, use dataset with NAinpsu filtered for psu==NA

####NAinpsu for dhs_nomiss

dhs_nomiss <- mutate(dhs_nomiss, 
                     psu = ifelse(psu==1, NA, psu))

summary(dhs_nomiss$psu)

dhs_nomiss_noNAinpsu <- filter(dhs_nomiss, is.na(psu)==F)

summary(dhs_nomiss_noNAinpsu$psu)

#create PSU ID in nomissPSU:
dhs_nomiss_noNAinpsu <- dhs_nomiss_noNAinpsu %>% 
  mutate(psu_str = as.character(psu), 
         psuid = str_c(state_dist_str, psu_str, sep = "_"))
dhs_nomiss_noNAinpsu$psuid <- as.factor(dhs_nomiss_noNAinpsu$psuid)

###create PSU ID in dhs_nomiss:
dhs_nomiss <- dhs_nomiss %>% 
  mutate(psu_str = as.character(psu), 
         psuid = str_c(state_dist_str, psu_str, sep = "_"))
dhs_nomiss$psuid <- as.factor(dhs_nomiss$psuid) 


###create PSU ID in dhs_nomiss_htn_only :
dhs_nomiss_htn_only <- dhs_nomiss_htn_only %>% 
  mutate(psu_str = as.character(psu), 
         psuid = str_c(state_dist_str, psu_str, sep = "_"))
dhs_nomiss_htn_only$psuid <- as.factor(dhs_nomiss_htn_only$psuid)

###create PSU ID in dhs_nomiss_htn_and_aware_only :
dhs_nomiss_htn_and_aware_only <- dhs_nomiss_htn_and_aware_only %>% 
  mutate(psu_str = as.character(psu), 
         psuid = str_c(state_dist_str, psu_str, sep = "_"))
dhs_nomiss_htn_and_aware_only$psuid <- as.factor(dhs_nomiss_htn_and_aware_only$psuid) 


###create PSU ID in dhs_nomiss_htn_and_treated_only :
dhs_nomiss_htn_and_treated_only <- dhs_nomiss_htn_and_treated_only %>% 
  mutate(psu_str = as.character(psu), 
         psuid = str_c(state_dist_str, psu_str, sep = "_"))
dhs_nomiss_htn_and_treated_only$psuid <- as.factor(dhs_nomiss_htn_and_treated_only$psuid) 




###Nainpsu for dhs_nomiss_htn_only

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only, 
                     psu = ifelse(psu==1, NA, psu))

summary(dhs_nomiss_htn_only$psu)

dhs_nomiss_htn_only_noNAinpsu <- filter(dhs_nomiss_htn_only, is.na(psu)==F)

summary(dhs_nomiss_htn_only_noNAinpsu$psu)

sum(is.na(dhs_nomiss$psu)==T)

###Nainpsu for dhs_nomiss_htn_and_aware_only

dhs_nomiss_htn_and_aware_only <- mutate(dhs_nomiss_htn_and_aware_only, 
                                   psu = ifelse(psu==1, NA, psu))

summary(dhs_nomiss_htn_and_aware_only$psu)

dhs_nomiss_htn_and_aware_only_noNAinpsu <- filter(dhs_nomiss_htn_and_aware_only, is.na(psu)==F)

summary(dhs_nomiss_htn_and_aware_only_noNAinpsu$psu)

sum(is.na(dhs_nomiss_htn_and_aware_only_noNAinpsu$psu)==T)

###Nainpsu for dhs_nomiss_htn_and_treated_only


dhs_nomiss_htn_and_treated_only <- mutate(dhs_nomiss_htn_and_treated_only, 
                                             psu = ifelse(psu==1, NA, psu))

summary(dhs_nomiss_htn_and_treated_only$psu)

dhs_nomiss_htn_and_treated_only_noNAinpsu <- filter(dhs_nomiss_htn_and_treated_only, is.na(psu)==F)

summary(dhs_nomiss_htn_and_treated_only_noNAinpsu$psu)

sum(is.na(dhs_nomiss_htn_and_treated_only_noNAinpsu$psu)==T)



###Create age_grp2 in htn only

dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                     age_grp2 = 
                       as.factor(ifelse(
                         age>=15 & age<20, "15-19",
                         ifelse(age>=20 & age<25, "20-24",
                                ifelse(age>=25 & age<30, "25-29",
                                       ifelse(age>=30 & age<35,"30-34", 
                                              ifelse(age>=35 & age<40, "35-39",
                                                     ifelse(age>=40 & age<45, "40-44",
                                                            ifelse(age>=45 & age<50, "45-49",
                                                                   ifelse(age>=50 & age<55, "50-54","54+"))))))))))
dhs_nomiss_htn_only <- mutate(dhs_nomiss_htn_only,
                                   age_grpOR = 
                                     as.factor(ifelse(
                                       age>=15 & age<20, "15-19",
                                       ifelse(age>=20 & age<25, "20-24",
                                              ifelse(age>=25 & age<30, "25-29",
                                                     ifelse(age>=30 & age<35,"30-34", 
                                                            ifelse(age>=35 & age<40, "35-39",
                                                                   ifelse(age>=40 & age<45, "40-44",
                                                                          ifelse(age>=45 & age<50, "45-49",
                                                                                 ifelse(age>=50 & age<55, "50-54","54+"))))))))))

dhs_nomiss_htn_only$age_grpOR <- factor(dhs_nomiss_htn_only$age_grpOR, levels = c("15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54"))

dhs_nomiss_htn_only <- within(dhs_nomiss_htn_only, age_grpOR <- relevel(age_grpOR, ref = "15-19"))


  dhs_nomiss_rural <- filter(dhs_nomiss, (urban_lab)=="Rural")
  dhs_nomiss_urban <- filter(dhs_nomiss, (urban_lab)=="Urban")
  dhs_nomiss_htn_only_rural <- filter(dhs_nomiss_htn_only, (urban_lab)=="Rural")
  dhs_nomiss_htn_only_urban <- filter(dhs_nomiss_htn_only, (urban_lab)=="Urban")
  
  dhs_nomiss_htn_only_rural_women <- filter(dhs_nomiss_htn_only, (urban_lab)=="Rural" & sex==1)
  dhs_nomiss_htn_only_rural_men <- filter(dhs_nomiss_htn_only, (urban_lab)=="Rural" & sex==0)
  
  dhs_nomiss_htn_only_urban_women <- filter(dhs_nomiss_htn_only, (urban_lab)=="Urban" & sex==1)
  dhs_nomiss_htn_only_urban_men <- filter(dhs_nomiss_htn_only, (urban_lab)=="Urban" & sex==0)
  
  dhs_nomiss_htn_only_women <- filter(dhs_nomiss_htn_only, sex==1)
  dhs_nomiss_htn_only_men <- filter(dhs_nomiss_htn_only,  sex==0)
  
  
  sum(is.na(dhs_nomiss$educat)==T)
  sum(is.na(dhs_nomiss$wealth_quintile_rurb)==T)
  sum(is.na(dhs_nomiss$marriednames)==T)
  sum(is.na(dhs_nomiss$age)==T)
  sum(is.na(dhs_nomiss$urban_lab)==T)

  
  dhs_nomiss <- mutate(dhs_nomiss,
                                only_smoke = ifelse((tobacco_smoked==1 & tobacco_smokeless==0), 1, 0))
  
  dhs_nomiss <- mutate(dhs_nomiss,
                       smoke_and_smokeless = ifelse((tobacco_smoked==1 & tobacco_smokeless==1), 1, 0))
  
  dhs_nomiss <- mutate(dhs_nomiss,
                       only_smokeless = ifelse((tobacco_smoked==0 & tobacco_smokeless==1), 1, 0))
  
  dhs_nomiss <- mutate(dhs_nomiss,
                       smoke_or_smokeless = ifelse((tobacco_smoked==1 | tobacco_smokeless==1), 1, 0))
  
  
  dhs_nomiss$tobacco_smokeless <- as.factor(dhs_nomiss$tobacco_smokeless)
  summary(dhs_nomiss$tobacco_smokeless)
  
  
  dhs_nomiss$tobacco_smoked <- as.factor(dhs_nomiss$tobacco_smoked)
  summary(dhs_nomiss$tobacco_smoked)
  
  
  dhs_nomiss$only_smoke <- as.factor(dhs_nomiss$only_smoke)
  summary(dhs_nomiss$only_smoke)
  
  dhs_nomiss$only_smokeless <- as.factor(dhs_nomiss$only_smokeless)
  summary(dhs_nomiss$only_smokeless)
  
  dhs_nomiss$smoke_and_smokeless <- as.factor(dhs_nomiss$smoke_and_smokeless)
  summary(dhs_nomiss$smoke_and_smokeless)
  
  dhs_nomiss$smoke_or_smokeless <- as.factor(dhs_nomiss$smoke_or_smokeless)
  summary(dhs_nomiss$smoke_or_smokeless)
  
  
  
  dhs_nomiss <- mutate(dhs_nomiss,
                       state_PCI = ifelse(ex_state_ind== "Andaman and Nicobar Islands",161595.035*(1/16.734), 
                                          ifelse(ex_state_ind== "Andhra Pradesh",93989.48897*(1/16.734),
                                                 ifelse(ex_state_ind== "Arunachal Pradesh",97887.8059*(1/16.734),
                                                        ifelse(ex_state_ind== "Assam",51099.8419*(1/16.734),
                                                               ifelse(ex_state_ind== "Bihar",33012.94996*(1/16.734),
                                                                      ifelse(ex_state_ind== "Chandigarh",275484.3905*(1/16.734),
                                                                             ifelse(ex_state_ind== "Chhattisgarh",72687.6339*(1/16.734),
                                                                                    ifelse(ex_state_ind== "Delhi",232979.7323*(1/16.734),
                                                                                           ifelse(ex_state_ind== "Goa",335245.0559*(1/16.734),
                                                                                                  ifelse(ex_state_ind== "Gujarat",126678.0115*(1/16.734),
                                                                                                         ifelse(ex_state_ind== "Haryana",153410.0874*(1/16.734),
                                                                                                                ifelse(ex_state_ind== "Himachal Pradesh",120305.5909*(1/16.734),
                                                                                                                       ifelse(ex_state_ind== "Jammu and Kashmir",69825.28608*(1/16.734),
                                                                                                                              ifelse(ex_state_ind== "Jharkhand",52374.28707*(1/16.734),
                                                                                                                                     ifelse(ex_state_ind== "Karnataka",100598.087*(1/16.734),
                                                                                                                                            ifelse(ex_state_ind== "Kerala",118625.7787*(1/16.734),
                                                                                                                                                   ifelse(ex_state_ind== "Madhya Pradesh",59858.0615*(1/16.734),
                                                                                                                                                          ifelse(ex_state_ind== "Maharashtra",134384.0679*(1/16.734),
                                                                                                                                                                 ifelse(ex_state_ind== "Manipur",50157.67944*(1/16.734),
                                                                                                                                                                        ifelse(ex_state_ind== "Meghalaya",73888.84451*(1/16.734),
                                                                                                                                                                               ifelse(ex_state_ind== "Mizoram",93847.46347*(1/16.734),
                                                                                                                                                                                      ifelse(ex_state_ind== "Nagaland",89709.28511*(1/16.734),
                                                                                                                                                                                             ifelse(ex_state_ind== "Odisha",65035.16039*(1/16.734),
                                                                                                                                                                                                    ifelse(ex_state_ind== "Puducherry",168892.5785*(1/16.734),
                                                                                                                                                                                                           ifelse(ex_state_ind== "Punjab",114462.0737*(1/16.734),
                                                                                                                                                                                                                  ifelse(ex_state_ind== "Rajasthan",75510.83915*(1/16.734),
                                                                                                                                                                                                                         ifelse(ex_state_ind== "Sikkim",202709.8957*(1/16.734),
                                                                                                                                                                                                                                ifelse(ex_state_ind== "Tamil Nadu",118402.3791*(1/16.734),
                                                                                                                                                                                                                                       ifelse(ex_state_ind== "Tripura",72973.88591*(1/16.734),
                                                                                                                                                                                                                                              ifelse(ex_state_ind== "Uttar Pradesh",43177.81353*(1/16.734),
                                                                                                                                                                                                                                                     ifelse(ex_state_ind== "Uttarakhand",121845.5702*(1/16.734),
                                                                                                                                                                                                                                                            ifelse(ex_state_ind== "West Bengal",77409.18859*(1/16.734),
                                                                                                                                                                                                                                                                   ifelse(ex_state_ind== "Telangana",111311.9409*(1/16.734),NA))))))))))))))))))))))))))))))))))
                                                                                                                                                                                                                                      
                     
  
  
```




```{r Output}
```
 
 
 
```{r heatmaps BMI}
  
  
  #####heatmaps BMI##
  
  #############urban and rural together
  
  ##### screened

  screened_htn_women_heatdat <- dhs_nomiss_htn_only %>%
    filter(is.na(bmi_group_large)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group_large, age_grp) %>% 
    mutate(screened_htn_indiv = 100*weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group_large, age_grp, screened_htn_indiv, bmi_group_large)
  
  # Now create the actual heatmap: 
  screened_htn_women_wealth_heat <- ggplot(data=screened_htn_women_heatdat, aes(x=bmi_group_large, y=age_grp)) +
    geom_tile(aes(fill=screened_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", screened_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  screened_htn_women_wealth_heat
  
  
  ###heatmap aware htn AS SUBSET
  
  ##### aware
  
  dhs_nomiss_htn_only <- dhs_nomiss_htn_only
  aware_htn_women_heatdat <- dhs_nomiss_htn_only %>%
    filter(is.na(bmi_group_large)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group_large, age_grp) %>% 
    mutate(aware_htn_indiv = 100*weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group_large, age_grp,  aware_htn_indiv, bmi_group_large, urban)
  
  # Now create the actual heatmap: 
  aware_htn_women_wealth_heat <- ggplot(data=aware_htn_women_heatdat, aes(x=bmi_group_large, y=age_grp)) +
    geom_tile(aes(fill=aware_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", aware_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
   
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  aware_htn_women_wealth_heat
  
  dev.copy(pdf,'htn aware wealth 25-3.pdf')
  dev.off()
  
  
  
  ###heatmap treated htn AS SUBSET
  
  
  ##### treated
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  treated_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(bmi_group_large)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group_large, age_grp) %>% 
    mutate(treated_htn_indiv = 100*weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group_large, age_grp,  treated_htn_indiv, bmi_group_large, urban)
  
  # Now create the actual heatmap: 
  treated_htn_women_wealth_heat <- ggplot(data=treated_htn_women_heatdat, aes(x=bmi_group_large, y=age_grp)) +
    geom_tile(aes(fill=treated_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", treated_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  treated_htn_women_wealth_heat
  
  dev.copy(pdf,'htn treated wealth 25-3.pdf')
  dev.off()
  
  
  
  
  #*************** controlled htn of htns   ******************
  
  
  #####all controlled
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  controlled_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(bmi_group_large)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group_large, age_grp) %>% 
    mutate(controlled_htn_indiv = 100*weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group_large, age_grp, controlled_htn_indiv, bmi_group_large, urban)
  
  # Now create the actual heatmap: 
  controlled_htn_women_wealth_heat <- ggplot(data=controlled_htn_women_heatdat, aes(x=bmi_group_large, y=age_grp)) +
    geom_tile(aes(fill=controlled_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", controlled_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  controlled_htn_women_wealth_heat
  
  dev.copy(pdf,'htn controlled wealth 25-3.pdf')
  dev.off()
  
  
```

```{r Heatmap BMI separate rural urban}
  
  ###BMI urban vs rural
  
  ###heatmap aware htn AS SUBSET

dhs_nomiss_htn_only_heat <- dhs_nomiss_htn_only
  
dhs_nomiss_htn_only_heat<- mutate(dhs_nomiss_htn_only_heat,
                     bmi_group = ifelse(bmi<18.5, "<18.5kg/m2",
                                        ifelse(bmi>=18.5 & bmi<23, "18.5-22.9 kg/m2",
                                               ifelse(bmi>=23 & bmi<25, "23.0-24.9 kg/m2",
                                                      ifelse(bmi>=25 & bmi<27.5, "25.0-27.4 kg/m2",
                                                             ifelse(bmi>=27.5 & bmi<30, "27.5-29.9 kg/m2",
                                                                    ifelse(bmi>=30, "\u2265 30.0 kg/m2", NA)))))))


dhs_nomiss_htn_only_heat$bmi_group <- factor(dhs_nomiss_htn_only_heat$bmi_group, levels = c("<18.5kg/m2", "18.5-22.9 kg/m2", "23.0-24.9 kg/m2", "25.0-27.4 kg/m2", "27.5-29.9 kg/m2", "\u2265 30.0 kg/m2"))
dhs_nomiss_htn_only_heat <- within(dhs_nomiss_htn_only_heat, bmi_group<- relevel(bmi_group, ref = "<18.5kg/m2"))
  
  ###screeened
  
  screened_htn_women_heatdat <- dhs_nomiss_htn_only_heat %>%
    filter(is.na(bmi_group)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group, age_grp, urban_lab) %>% 
    mutate(screened_htn_indiv = 100*weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group, age_grp, screened_htn_indiv, bmi_group, urban_lab)
  
  # Now create the actual heatmap: 
  screened_htn_women_wealth_heat <- ggplot(data=screened_htn_women_heatdat, aes(x=bmi_group, y=age_grp)) +
    geom_tile(aes(fill=screened_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", screened_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(6/4)
  screened_htn_women_wealth_heat
  
  ##### aware
  
  dhs_nomiss_htn_only_heat <- dhs_nomiss_htn_only_heat
  aware_htn_women_heatdat <- dhs_nomiss_htn_only_heat %>%
    filter(is.na(bmi_group)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group, age_grp, urban_lab) %>% 
    mutate(aware_htn_indiv = 100*weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group, age_grp, urban_lab, aware_htn_indiv, bmi_group, urban)
  
  # Now create the actual heatmap: 
  aware_htn_women_wealth_heat <- ggplot(data=aware_htn_women_heatdat, aes(x=bmi_group, y=age_grp)) +
    geom_tile(aes(fill=aware_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", aware_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(6/4)
  aware_htn_women_wealth_heat
  
  dev.copy(pdf,'htn aware wealth 25-3.pdf')
  dev.off()
  
  
  
  ###heatmap treated htn AS SUBSET
  
  
  ##### treated
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only_heat
  treated_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(bmi_group)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group, age_grp, urban_lab) %>% 
    mutate(treated_htn_indiv = 100*weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group, age_grp, urban_lab, treated_htn_indiv, bmi_group, urban)
  
  # Now create the actual heatmap: 
  treated_htn_women_wealth_heat <- ggplot(data=treated_htn_women_heatdat, aes(x=bmi_group, y=age_grp)) +
    geom_tile(aes(fill=treated_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", treated_htn_indiv)), size=5) +
    facet_grid(. ~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(6/4)
  treated_htn_women_wealth_heat
  
  dev.copy(pdf,'htn treated wealth 25-3.pdf')
  dev.off()
  
  
  
  
  #*************** controlled htn of htns   ******************
  
  
  #####all controlled
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only_heat
  controlled_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(bmi_group)==FALSE & is.na(age)==FALSE) %>% 
    group_by( bmi_group, age_grp, urban_lab) %>% 
    mutate(controlled_htn_indiv = 100*weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( bmi_group, age_grp, urban_lab, controlled_htn_indiv, bmi_group, urban)
  
  # Now create the actual heatmap: 
  controlled_htn_women_wealth_heat <- ggplot(data=controlled_htn_women_heatdat, aes(x=bmi_group, y=age_grp)) +
    geom_tile(aes(fill=controlled_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", controlled_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "BMI",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(6/4)
  controlled_htn_women_wealth_heat
  
  dev.copy(pdf,'htn controlled wealth 25-3.pdf')
  dev.off()
  
```

```{r Heatmap by Household Wealth Quintile Hypertension prevalence  men women separately}
  

###heatmap htn
  
  dhs_nomiss_men_only <- dhs_nomiss
  htn_men_heatdat <- dhs_nomiss_men_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( wealth_quintile_rurb, age_grp, urban) %>% 
    mutate(htn_indiv = 100*weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab,female_lab, age_grp, urban_lab, htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  htn_men_wealth_heat <- ggplot(data=htn_men_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp)) +
    geom_tile(aes(fill=htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", htn_indiv)), size=5) +
    facet_grid(~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = -1) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  htn_men_wealth_heat
  
  
  
  #####men only htn
  
  dhs_nomiss_men_only <- filter(dhs_nomiss, (sex)==0) 
  htn_men_heatdat <- dhs_nomiss_men_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( female_lab, wealth_quintile_rurb, age_grp, urban) %>% 
    mutate(htn_indiv = 100*weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab,female_lab, age_grp, urban_lab, htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  htn_men_wealth_heat <- ggplot(data=htn_men_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp)) +
    geom_tile(aes(fill=htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", htn_indiv)), size=5) +
    facet_grid(~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = -1) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  htn_men_wealth_heat
  
  dev.copy(pdf,'htn men.pdf')
  dev.off()
  
  
  #####Women only htn
  
  dhs_nomiss_women_only <- filter(dhs_nomiss, (sex)==1) 
  htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( female_lab, wealth_quintile_rurb, age_grp_women, urban) %>% 
    mutate(htn_indiv = 100*weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab,female_lab, age_grp_women, urban_lab, htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  htn_women_wealth_heat <- ggplot(data=htn_women_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp_women)) +
    geom_tile(aes(fill=htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", htn_indiv)), size=5) +
    facet_grid(~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = -1) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  htn_women_wealth_heat
  
  dev.copy(pdf,'htn women.pdf')
  dev.off()
  
  
  
```

```{r Heatmaps by wealth quintile cascade}
  #####Screened as subset

  
  ##### screened
  
  dhs_nomiss_htn_only <- dhs_nomiss_htn_only
  screened_htn_women_heatdat <- dhs_nomiss_htn_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( wealth_quintile_rurb, age_grp, urban_lab) %>% 
    mutate(screened_htn_indiv = 100*weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab, age_grp, urban_lab, screened_htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  screened_htn_women_wealth_heat <- ggplot(data=screened_htn_women_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp)) +
    geom_tile(aes(fill=screened_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", screened_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  screened_htn_women_wealth_heat
  
  dev.copy(pdf,'htn screened wealth 25-3.pdf')
  dev.off()
  
  
  
  ###heatmap aware htn AS SUBSET
  
  ##### aware
  
  dhs_nomiss_htn_only <- dhs_nomiss_htn_only
  aware_htn_women_heatdat <- dhs_nomiss_htn_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( wealth_quintile_rurb, age_grp, urban_lab) %>% 
    mutate(aware_htn_indiv = 100*weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab, age_grp, urban_lab, aware_htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  aware_htn_women_wealth_heat <- ggplot(data=aware_htn_women_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp)) +
    geom_tile(aes(fill=aware_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", aware_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  aware_htn_women_wealth_heat
  
  dev.copy(pdf,'htn aware wealth 25-3.pdf')
  dev.off()
  
  
  
  ###heatmap treated htn AS SUBSET
  
  
  ##### treated
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  treated_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( wealth_quintile_rurb, age_grp, urban_lab) %>% 
    mutate(treated_htn_indiv = 100*weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab, age_grp, urban_lab, treated_htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  treated_htn_women_wealth_heat <- ggplot(data=treated_htn_women_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp)) +
    geom_tile(aes(fill=treated_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", treated_htn_indiv)), size=5) +
    facet_grid(. ~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  treated_htn_women_wealth_heat
  
  dev.copy(pdf,'htn treated wealth 25-3.pdf')
  dev.off()
  
  
  
  
  #*************** controlled htn of htns   ******************
  
  
  #####all controlled
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  controlled_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(wealth_quintile_rurb)==FALSE & is.na(age)==FALSE) %>% 
    group_by( wealth_quintile_rurb, age_grp, urban_lab) %>% 
    mutate(controlled_htn_indiv = 100*weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( wealth_quintile_rurb_lab, age_grp, urban_lab, controlled_htn_indiv, wealth_quintile_rurb, urban)
  
  # Now create the actual heatmap: 
  controlled_htn_women_wealth_heat <- ggplot(data=controlled_htn_women_heatdat, aes(x=wealth_quintile_rurb_lab, y=age_grp)) +
    geom_tile(aes(fill=controlled_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", controlled_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Household Wealth Quintile",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(5/4)
  controlled_htn_women_wealth_heat
  
  dev.copy(pdf,'htn controlled wealth 25-3.pdf')
  dev.off()
  
```

```{r heatmaps by education hypertension men and women separately}
  
  ##Education##
  
  ###heatmap htn Education
  
  #####Men only htn EDUCATION
  
  dhs_nomiss_men_only <- filter(dhs_nomiss, (sex)==0) 
  htn_men_heatdat <- dhs_nomiss_men_only %>%
    filter(is.na(educat)==FALSE & is.na(age_grp)==FALSE) %>% 
    group_by( educat, age_grp, urban) %>% 
    mutate(htn_indiv = 100*weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select(age_grp, educat, urban_lab, htn_indiv, educatnames, urban)
  
  # Now create the actual heatmap: 
  htn_men_wealth_heat <- ggplot(data=htn_men_heatdat, aes(x=educatnames, y=age_grp)) +
    geom_tile(aes(fill=htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", htn_indiv)), size=5) +
    facet_grid(. ~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = -1) +
    theme_classic() +
    labs(x = "Education",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  htn_men_wealth_heat
  
  dev.copy(pdf,'educat htn men.pdf')
  dev.off()
  
  
  #####Women only htn EDUCATION
  
  dhs_nomiss_women_only <- filter(dhs_nomiss, (sex)==1) 
  htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(educat)==FALSE & is.na(age_grp_women)==FALSE) %>% 
    group_by( educat, age_grp_women, urban) %>% 
    mutate(htn_indiv = 100*weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( educatnames, age_grp_women, urban_lab, htn_indiv, educat, urban)
  
  # Now create the actual heatmap: 
  htn_women_wealth_heat <- ggplot(data=htn_women_heatdat, aes(x=educatnames, y=age_grp_women)) +
    geom_tile(aes(fill=htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", htn_indiv)), size=5) +
    facet_grid(. ~urban_lab) +
    scale_fill_distiller(palette = "RdYlGn", direction = -1) +
    theme_classic() +
    labs(x = "Education",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  htn_women_wealth_heat
  
  dev.copy(pdf,'educat htn women.pdf')
  dev.off()
  
  
```

```{r heatmap by education cascade}
  

  
  ####screened education
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  screened_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(educat)==FALSE & is.na(age_grp)==FALSE) %>% 
    group_by( educat, age_grp, urban_lab) %>% 
    mutate(screened_htn_indiv = 100*weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( educat, age_grp, urban_lab, screened_htn_indiv, educatnames, urban)
  
  # Now create the actual heatmap: 
  screened_htn_women_wealth_heat <- ggplot(data=screened_htn_women_heatdat, aes(x=educatnames, y=age_grp)) +
    geom_tile(aes(fill=screened_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", screened_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Education",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  screened_htn_women_wealth_heat
  
  dev.copy(pdf,'htn educat screened 3-25.pdf')
  dev.off()
  
  #####aware EDUCATION
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  aware_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(educat)==FALSE & is.na(age_grp)==FALSE) %>% 
    group_by( educat, age_grp, urban_lab) %>% 
    mutate(aware_htn_indiv = 100*weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( educat, age_grp, urban_lab, aware_htn_indiv, educatnames, urban)
  
  # Now create the actual heatmap: 
  aware_htn_women_wealth_heat <- ggplot(data=aware_htn_women_heatdat, aes(x=educatnames, y=age_grp)) +
    geom_tile(aes(fill=aware_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", aware_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Education",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  aware_htn_women_wealth_heat
  
  dev.copy(pdf,'htn educat aware 3-25.pdf')
  dev.off()
  
  
  ###heatmap treated htn AS SUBSET EDUCATION
  
  #####treated EDUCATION
  
  dhs_nomiss_men_only <- dhs_nomiss_htn_only 
  treated_htn_men_heatdat <- dhs_nomiss_men_only %>%
    filter(is.na(educat)==FALSE & is.na(age_grp)==FALSE) %>% 
    group_by( educat, age_grp, urban_lab) %>% 
    mutate(treated_htn_indiv = 100*weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( educat, age_grp, urban_lab, treated_htn_indiv, educatnames, urban)
  
  # Now create the actual heatmap: 
  treated_htn_men_wealth_heat <- ggplot(data=treated_htn_men_heatdat, aes(x=educatnames, y=age_grp)) +
    geom_tile(aes(fill=treated_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", treated_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Education",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  treated_htn_men_wealth_heat
  
  dev.copy(pdf,'htn educat treated 3-25.pdf')
  dev.off()
  
  
  
  #### controlled EDUCATION
  
  dhs_nomiss_women_only <- dhs_nomiss_htn_only
  controlled_htn_women_heatdat <- dhs_nomiss_women_only %>%
    filter(is.na(educat)==FALSE & is.na(age_grp)==FALSE) %>% 
    group_by(educat, age_grp, urban_lab) %>% 
    mutate(controlled_htn_indiv = 100*weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)) %>% 
    filter(row_number()==1) %>%   
    dplyr::select( educat, age_grp, urban_lab, controlled_htn_indiv, educatnames, urban, female_lab)
  
  # Now create the actual heatmap: 
  controlled_htn_women_wealth_heat <- ggplot(data=controlled_htn_women_heatdat, aes(x=educatnames, y=age_grp)) +
    geom_tile(aes(fill=controlled_htn_indiv)) + 
    geom_text(aes(label=sprintf("%1.1f", controlled_htn_indiv)), size=5) +
    scale_fill_distiller(palette = "RdYlGn", direction = 1) +
    facet_grid(. ~urban_lab) +
    theme_classic() +
    labs(x = "Education",
         y = "Age Group, y",
         fill="") +
    theme(axis.text.x =element_text(size=15, face="bold", family="Times", angle=45, hjust=1),
          axis.text.y =element_text(size=15, face="bold", family="Times"),
          axis.title=element_text(size=22, face="italic", family="Times"),
          legend.title=element_blank(),
          legend.text=element_text(size=18, family="Times"),
          strip.text=element_text(size=18, family="Times", face="bold"), 
          panel.spacing = unit(2, "lines"),
          axis.title.x = element_text(margin = margin(t = 20), family="Times"),
          axis.title.y = element_text(margin = margin(r = 20), family="Times"),
          plot.title = element_text(size = 25, hjust = 0.5, family="Times", face = "bold")) +
    coord_fixed(4/4)
  controlled_htn_women_wealth_heat
  
  dev.copy(pdf,'htn educat controlled 3-25.pdf')
  dev.off()

```

```{r regressions without clustering but with interaction educat or wealth FOR REGRESSION FIGURE}
###Regression

#Overnight

  
  ####Regressions without clustering but with interaction educat
  
  
#  multiv_feglm <- glm(formula = ex_htn_broad_ind ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + #urban + d_id + educat:age_grpOR + educat:urban + age_grpOR:urban, data=dhs_nomiss, family=binomial(link="logit"))
  #exp(cbind(OR = coef(multiv_feglm), confint(multiv_feglm)))[2:20,]
  
  #save(file="glmhtn_03_22",multiv_feglm)
 #results_df <-summary.glm(multiv_feglm)$coefficients
  #write.csv(results_df, "resultsORglmhtn_03_22.csv")
  
  multiv_feglmscreened <- glm(formula = htn_screened_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + educat:age_grpOR + educat:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.screened_2018_03_22",multiv_feglmscreened)
  results_screened <-summary.glm(multiv_feglmscreened)$coefficients
  write.csv(results_screened, "resultsORglm_screened_2018_03_22.csv")
  
  
  multiv_feglmtreated <- glm(formula = htn_treated_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + educat:age_grpOR + educat:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.treated_2018_03_22",multiv_feglmtreated)
  results_treated <-summary.glm(multiv_feglmtreated)$coefficients
  write.csv(results_treated, "resultsORglm_treated_2018_03_22.csv")
  
  multiv_feglmaware <- glm(formula = htn_aware_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + educat:age_grpOR + educat:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.aware_2018_03_22",multiv_feglmaware)
  results_aware <-summary.glm(multiv_feglmaware)$coefficients
  write.csv(results_aware, "resultsORglm_aware_2018_03_22.csv")
  
  multiv_feglmcontrolled <- glm(formula = htn_controlled_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + educat:age_grpOR + educat:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.controlled_2018_03_22",multiv_feglmcontrolled)
  results_controlled <-summary.glm(multiv_feglmcontrolled)$coefficients
  write.csv(results_controlled, "resultsORglm_controlled_2018_03_22.csv")
  
  
  ###Regression without clustering but with interaction wealth
  
  multiv_feglm <- glm(formula = ex_htn_broad_ind ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss, family=binomial(link="logit"))
  #exp(cbind(OR = coef(multiv_feglm), confint(multiv_feglm)))[2:20,]
  
  #save(file="glmhtn_03_22",multiv_feglm)
  results_df <-summary.glm(multiv_feglm)$coefficients
  write.csv(results_df, "resultsORglmhtn_03_22.csv")
  
  
  multiv_feglmtreated <- glm(formula = htn_treated_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.treated_2018_03_22",multiv_feglmtreated)
  results_treated <-summary.glm(multiv_feglmtreated)$coefficients
  write.csv(results_treated, "resultsORglm_treated_2018_03_22.csv")
  
  multiv_feglmscreened <- glm(formula = htn_screened_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.screened_2018_03_22",multiv_feglmscreened)
  results_screened <-summary.glm(multiv_feglmscreened)$coefficients
  write.csv(results_screened, "resultsORglm_screened_2018_03_22.csv")
  
  multiv_feglmaware <- glm(formula = htn_aware_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.aware_2018_03_22",multiv_feglmaware)
  results_aware <-summary.glm(multiv_feglmaware)$coefficients
  write.csv(results_aware, "resultsORglm_aware_2018_03_22.csv")
  
  multiv_feglmcontrolled <- glm(formula = htn_controlled_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, family=binomial(link="logit"))
  
  #save(file="glm.controlled_2018_03_22",multiv_feglmcontrolled)
  results_controlled <-summary.glm(multiv_feglmcontrolled)$coefficients
  write.csv(results_controlled, "resultsORglm_controlled_2018_03_22.csv")
  
  
```


```{r regressions wealth with weight by men and women FOR REGRESSION FIGURE}
  
##################wealth regressions with sample weight
  
  
  multiv_weight_feglmtreated <- glm(formula = htn_treated_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, weights= p_wt_new, family=binomial(link="logit"))
  

  
  multiv_weight_feglmscreened <- glm(formula = htn_screened_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, weights= p_wt_new, family=binomial(link="logit"))
  

  
  multiv_weight_feglmaware <- glm(formula = htn_aware_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, weights= p_wt_new, family=binomial(link="logit"))
  

  
  multiv_weight_feglmcontrolled <- glm(formula = htn_controlled_dbl ~ sex + age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only, weights= p_wt_new, family=binomial(link="logit"))
  
###############wealth regressions women
  
  
  multiv_women_feglmtreated <- glm(formula = htn_treated_dbl ~   age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))
  
  
  
  multiv_women_feglmscreened <- glm(formula = htn_screened_dbl ~   age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))
  
  
  
  multiv_women_feglmaware <- glm(formula = htn_aware_dbl ~  age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_women,  family=binomial(link="logit"))
  
  
  
  multiv_women_feglmcontrolled <- glm(formula = htn_controlled_dbl ~  age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))
  
  #########wealth regressions men
  
  
  multiv_men_feglmtreated <- glm(formula = htn_treated_dbl ~   age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_men, family=binomial(link="logit"))
  
  
  
  multiv_men_feglmscreened <- glm(formula = htn_screened_dbl ~   age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_men,  family=binomial(link="logit"))
  
  
  
  multiv_men_feglmaware <- glm(formula = htn_aware_dbl ~  age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_men, family=binomial(link="logit"))
  
  
  
  multiv_men_feglmcontrolled <- glm(formula = htn_controlled_dbl ~  age_grpOR + married + wealth_quintile_rurb + educat + urban + d_id + wealth_quintile_rurb:age_grpOR + wealth_quintile_rurb:urban + age_grpOR:urban, data=dhs_nomiss_htn_only_men,family=binomial(link="logit"))
  
  

####Regressions with clustering


#multiv_feclust <- glm.cluster(formula = ex_htn_broad_ind ~ sex + age_grp2 + married + wealth_quintile_rurb + educat + urban + d_id, cluster="d_id", data=dhs_nomiss, family=binomial(link="logit"))
#exp(cbind(OR = coef(multiv_feclust), confint(multiv_feclust)))[2:656,] 

#save(file="glm.cluster2018_03_22",multiv_feclust)
#results_clust <-summary(multiv_feclust)
#write.csv(results_clust, "resultsglmclust2018_03_22.csv")

#multiv_feclustaware <- glm.cluster(formula = htn_aware_dbl ~ sex + age_grp2 + married + wealth_quintile_rurb + educat + urban + d_id, cluster="d_id", data=dhs_nomiss_htn_only, family=binomial(link="logit"))
#exp(cbind(OR = coef(multiv_feclust), confint(multiv_feclust)))[2:656,] 

#save(file="glm.clusteraware2018_03_22",multiv_feclustaware)
#results_clustaware <-summary(multiv_feclustaware)
#write.csv(results_clustaware, "resultsglmclustaware2018_03_22.csv")

#multiv_feclusttreated <- glm.cluster(formula = htn_treated_dbl ~ sex + age_grp2 + married + wealth_quintile_rurb + educat + urban + d_id, cluster="d_id", data=dhs_nomiss_htn_only, family=binomial(link="logit"))
#exp(cbind(OR = coef(multiv_feclust), confint(multiv_feclust)))[2:656,] 

#save(file="glm.clustertreated2018_03_22",multiv_feclusttreated)
#results_clusttreated <-summary(multiv_feclusttreated)
#write.csv(results_clusttreated, "resultsglmclusttreated2018_03_22.csv")

#multiv_feclustcontrolled <- glm.cluster(formula = htn_controlled_dbl ~ sex + age_grp2 + married + wealth_quintile_rurb + educat + urban + d_id, cluster="d_id", data=dhs_nomiss_htn_only, family=binomial(link="logit"))
#exp(cbind(OR = coef(multiv_feclust), confint(multiv_feclust)))[2:656,] 

#save(file="glm.clustercontrolled2018_03_22",multiv_feclustcontrolled)
#results_clustcontrolled <-summary(multiv_feclustcontrolled)
#write.csv(results_clustcontrolled, "resultsglmclustcontrolled2018_03_22.csv")

  multimorbidity <- glm.cluster(formula = multi_morbid_dbl ~ age_grp + wealth_quintile_rurb_lab + educatnames + married  + sex + zone_new + district_medianwealth,  cluster="psu", data=dhs_nomiss_urban, family=poisson(link="log"))
  
```

```{r regressions clustered d_id and FE urban and rural separately}
  
  
#clustered regressions for urban and rural separately#


#Rural htn

#multiv_feclust_htn_rural <- glm.cluster(formula = ex_htn_broad_ind ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_rural, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_rural), confint(multiv_feclust_htn_rural))) 
#htn_rural <- exp(cbind(OR = coef(multiv_feclust_htn_rural), confint(multiv_feclust_htn_rural))) 
#write.csv(htn_rural, "OR htn ruralpoisson.csv")

#CI_multiv_feclust_htn_rural <- confint(multiv_feclust_htn_rural)
#write.csv(CI_multiv_feclust_htn_rural, "CI rural htnpoisson.csv")



#save(file="glm.clusthtnrural2018_03_22",multiv_feclust_htn_rural)
#results_clusthtnrural <-summary(multiv_feclust_htn_rural)


#results_clusthtnrural_CI <- as.data.frame(results_clusthtnrural)

#write.csv(results_clusthtnrural, "resultsglmclusthtnrural2018_03_22poisson.csv")

#Urban htn

#multiv_feclust_htn_urban <- glm.cluster(formula = ex_htn_broad_ind ~  age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#htn_urban <- exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#write.csv(htn_urban, "OR htn urbanpoisson.csv")


#CI_multiv_feclust_htn_urban <- confint(multiv_feclust_htn_urban)
##write.csv(CI_multiv_feclust_htn_urban, "CI urban htnpoisson.csv")



#save(file="glm.clusthtnurban2018_03_22",multiv_feclust_htn_urban)
#results_clusthtnurban <-summary(multiv_feclust_htn_urban)
#write.csv(results_clusthtnurban, "resultsglmclusthtnurban2018_03_22poisson.csv")

#Rural screened
multiv_feclustscreened_rural <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural))) 
screened_rural <- exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural)))
write.csv(screened_rural, "OR screened ruralclustered d_id FEpoisson.csv")

CI_multiv_feclustscreened_rural <- confint(multiv_feclustscreened_rural)
write.csv(CI_multiv_feclustscreened_rural, "CI rural screenedclustered d_id FEpoisson.csv")

save(file="glm.clusterscreenedrural2018_03_22",multiv_feclustscreened_rural)
results_clustscreenedrural <-summary(multiv_feclustscreened_rural)
write.csv(results_clustscreenedrural, "resultsglmclustscreenedrural2018_03_22clustered d_id FEpoisson.csv")

#Urban screened
multiv_feclustscreened_urban <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban))) 
screened_urban <- exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban)))
write.csv(screened_urban, "OR screened urbanclustered d_id FEpoisson.csv")


CI_multiv_feclustscreened_urban <- confint(multiv_feclustscreened_urban)
write.csv(CI_multiv_feclustscreened_urban, "CI urban screenedclustered d_id FEpoisson.csv")


save(file="glm.clusterscreenedurban2018_03_22",multiv_feclustscreened_urban)
results_clustscreenedurban <-summary(multiv_feclustscreened_urban)
write.csv(results_clustscreenedurban, "resultsglmclustscreenedurban2018_03_22clustered d_id FEpoisson.csv")


#Rural aware
multiv_feclustaware_rural <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural))) 
aware_rural <- exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural)))
write.csv(aware_rural, "OR aware ruralclustered d_id FEpoisson.csv")

 CI_multiv_feclustaware_rural <- confint(multiv_feclustaware_rural)
write.csv(CI_multiv_feclustaware_rural, "CI rural awareclustered d_id FEpoisson.csv")

save(file="glm.clusterawarerural2018_03_22",multiv_feclustaware_rural)
results_clustawarerural <-summary(multiv_feclustaware_rural)
write.csv(results_clustawarerural, "resultsglmclustawarerural2018_03_22clustered d_id FEpoisson.csv")

#Urban aware
multiv_feclustaware_urban <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban))) 
aware_urban <- exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban)))
write.csv(aware_urban, "OR aware urbanclustered d_id FEpoisson.csv")


CI_multiv_feclustaware_urban <- confint(multiv_feclustaware_urban)
write.csv(CI_multiv_feclustaware_urban, "CI urban awareclustered d_id FEpoisson.csv")


save(file="glm.clusterawareurban2018_03_22",multiv_feclustaware_urban)
results_clustawareurban <-summary(multiv_feclustaware_urban)
write.csv(results_clustawareurban, "resultsglmclustawareurban2018_03_22clustered d_id FEpoisson.csv")


#rural treated

multiv_feclusttreated_rural <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural)))
treated_rural <- exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural))) 
write.csv(treated_rural, "OR treated ruralclustered d_id FEpoisson.csv")

CI_multiv_feclusttreated_rural <- confint(multiv_feclusttreated_rural)
write.csv(CI_multiv_feclusttreated_rural, "CI rural treatedclustered d_id FEpoisson.csv")


save(file="glm.clustertreatedrural2018_03_22",multiv_feclusttreated_rural)
results_clusttreatedrural <-summary(multiv_feclusttreated_rural)
write.csv(results_clusttreatedrural, "resultsglmclusttreatedrural2018_03_22clustered d_id FEpoisson.csv")

#urban treated

multiv_feclusttreated_urban <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban))) 
treated_urban <- exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban)))
write.csv(treated_urban, "OR treated urbanclustered d_id FEpoisson.csv")

CI_multiv_feclusttreated_urban <- confint(multiv_feclusttreated_urban)
write.csv(CI_multiv_feclusttreated_urban, "CI urban treatedclustered d_id FEpoisson.csv")


save(file="glm.clustertreatedurban2018_03_22",multiv_feclusttreated_urban)
results_clusttreatedurban <-summary(multiv_feclusttreated_urban)
write.csv(results_clusttreatedurban, "resultsglmclusttreatedurban2018_03_22clustered d_id FEpoisson.csv")

#rural controlled


multiv_feclustcontrolled_rural <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
controlled_rural <- exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
write.csv(controlled_rural, "OR controlled ruralclustered d_id FEpoisson.csv")

CI_multiv_feclustcontrolled_rural <- confint(multiv_feclustcontrolled_rural)
write.csv(CI_multiv_feclustcontrolled_rural, "CI rural controlledclustered d_id FEpoisson.csv")


save(file="glm.clustercontrolledrural2018_03_22",multiv_feclustcontrolled_rural)
results_clustcontrolledrural <-summary(multiv_feclustcontrolled_rural)
write.csv(results_clustcontrolledrural, "resultsglmclustcontrolledrural2018_03_22clustered d_id FEpoisson.csv")

#urban controlled

multiv_feclustcontrolled_urban <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + d_id, cluster="d_id", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
controlled_urban <- exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
write.csv(controlled_urban, "OR controlled urbanclustered d_id FEpoisson.csv")

CI_multiv_feclustcontrolled_urban <- confint(multiv_feclustcontrolled_urban)
write.csv(CI_multiv_feclustcontrolled_urban, "CI urban controlledclustered d_id FEpoisson.csv")

save(file="glm.clustercontrolledurban2018_03_22",multiv_feclustcontrolled_urban)
results_clustcontrolledurban <-summary(multiv_feclustcontrolled_urban)
write.csv(results_clustcontrolledurban, "resultsglmclustcontrolledurban2018_03_22clustered d_id FEpoisson.csv")


```


```{r regressions  FE and PSU clustering urban and rural separately}

#clustered regressions for urban and rural separately, no FE but PSU-Clustering#


#Rural htn

#multiv_feclust_htn_rural <- glm.cluster(formula = ex_htn_broad_ind ~ age_grp2 + wealth_quintile_rurb + educatnames #+ married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_rural, #family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_rural), confint(multiv_feclust_htn_rural))) 
#htn_rural <- exp(cbind(OR = coef(multiv_feclust_htn_rural), confint(multiv_feclust_htn_rural))) 
#write.csv(htn_rural, "OR htn ruralpoisson.csv")

#CI_multiv_feclust_htn_rural <- confint(multiv_feclust_htn_rural)
#write.csv(CI_multiv_feclust_htn_rural, "CI rural htnpoisson.csv")



#save(file="glm.clusthtnrural2018_03_22",multiv_feclust_htn_rural)
#results_clusthtnrural <-summary(multiv_feclust_htn_rural)


#results_clusthtnrural_CI <- as.data.frame(results_clusthtnrural)

#write.csv(results_clusthtnrural, "resultsglmclusthtnrural2018_03_22poisson.csv")

#Urban htn

#multiv_feclust_htn_urban <- glm.cluster(formula = ex_htn_broad_ind ~  age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#htn_urban <- exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#write.csv(htn_urban, "OR htn urbanpoisson.csv")


#CI_multiv_feclust_htn_urban <- confint(multiv_feclust_htn_urban)
#write.csv(CI_multiv_feclust_htn_urban, "CI urban htnpoisson.csv")




#save(file="glm.clusthtnurban2018_03_22",multiv_feclust_htn_urban)
#results_clusthtnurban <-summary(multiv_feclust_htn_urban)
#write.csv(results_clusthtnurban, "resultsglmclusthtnurban2018_03_22poisson.csv")

#Rural screened
multiv_feclustscreened_rural <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural))) 
screened_rural <- exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural)))
write.csv(screened_rural, "OR screened ruralpsu clustering d_idpoisson.csv")

#save(file="glm.clusterscreenedrural2018_03_22",multiv_feclustscreened_rural)
results_clustscreenedrural <-summary(multiv_feclustscreened_rural)
write.csv(results_clustscreenedrural, "resultsglmclustscreenedrural2018_03_22psu clustering d_idpoisson.csv")

#Urban screened
multiv_feclustscreened_urban <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban))) 
screened_urban <- exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban)))
write.csv(screened_urban, "OR screened urbanpsu clustering d_idpoisson.csv")


#save(file="glm.clusterscreenedurban2018_03_22",multiv_feclustscreened_urban)
results_clustscreenedurban <-summary(multiv_feclustscreened_urban)
write.csv(results_clustscreenedurban, "resultsglmclustscreenedurban2018_03_22psu clustering d_idpoisson.csv")


#Rural aware
multiv_feclustaware_rural <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural))) 
aware_rural <- exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural)))
write.csv(aware_rural, "OR aware ruralpsu clustering d_idpoisson.csv")

#save(file="glm.clusterawarerural2018_03_22",multiv_feclustaware_rural)
results_clustawarerural <-summary(multiv_feclustaware_rural)
write.csv(results_clustawarerural, "resultsglmclustawarerural2018_03_22psu clustering d_idpoisson.csv")

#Urban aware
multiv_feclustaware_urban <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban))) 
aware_urban <- exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban)))
write.csv(aware_urban, "OR aware urbanpsu clustering d_idpoisson.csv")


#save(file="glm.clusterawareurban2018_03_22",multiv_feclustaware_urban)
results_clustawareurban <-summary(multiv_feclustaware_urban)
write.csv(results_clustawareurban, "resultsglmclustawareurban2018_03_22psu clustering d_idpoisson.csv")


#rural treated

multiv_feclusttreated_rural <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural)))
treated_rural <- exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural))) 
write.csv(treated_rural, "OR treated ruralpsu clustering d_idpoisson.csv")


#save(file="glm.clustertreatedrural2018_03_22",multiv_feclusttreated_rural)
results_clusttreatedrural <-summary(multiv_feclusttreated_rural)
write.csv(results_clusttreatedrural, "resultsglmclusttreatedrural2018_03_22psu clustering d_idpoisson.csv")

#urban treated

multiv_feclusttreated_urban <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban))) 
treated_urban <- exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban)))
write.csv(treated_urban, "OR treated urbanpsu clustering d_idpoisson.csv")


#save(file="glm.clustertreatedurban2018_03_22",multiv_feclusttreated_urban)
results_clusttreatedurban <-summary(multiv_feclusttreated_urban)
write.csv(results_clusttreatedurban, "resultsglmclusttreatedurban2018_03_22psu clustering d_idpoisson.csv")

#rural controlled


multiv_feclustcontrolled_rural <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
controlled_rural <- exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
write.csv(controlled_rural, "OR controlled ruralpsu clustering d_idpoisson.csv")


#save(file="glm.clustercontrolledrural2018_03_22",multiv_feclustcontrolled_rural)
results_clustcontrolledrural <-summary(multiv_feclustcontrolled_rural)
write.csv(results_clustcontrolledrural, "resultsglmclustcontrolledrural2018_03_22psu clustering d_idpoisson.csv")

#urban controlled

multiv_feclustcontrolled_urban <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
controlled_urban <- exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
write.csv(controlled_urban, "OR controlled urbanpsu clustering d_idpoisson.csv")

#save(file="glm.clustercontrolledurban2018_03_22",multiv_feclustcontrolled_urban)
results_clustcontrolledurban <-summary(multiv_feclustcontrolled_urban)
write.csv(results_clustcontrolledurban, "resultsglmclustcontrolledurban2018_03_22psu clustering d_idpoisson.csv")


```

```{r regression men only : psu clustering : urban vs. rural}

#PSU clustering, urban vs rural, Men#

#Rural screened
multiv_feclustscreened_rural <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural))) 
screened_rural <- exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural)))
write.csv(screened_rural, "OR screened ruralmenpsu clusteringpoisson.csv")

CI_multiv_feclustscreened_rural <- confint(multiv_feclustscreened_rural)
write.csv(CI_multiv_feclustscreened_rural, "CI rural screenedmenpsu clusteringpoisson.csv")

#save(file="glm.clusterscreenedrural2018_03_22",multiv_feclustscreened_rural)
results_clustscreenedrural <-summary(multiv_feclustscreened_rural)
write.csv(results_clustscreenedrural, "resultsglmclustscreenedrural2018_03_22menpsu clusteringpoisson.csv")

#Urban screened
multiv_feclustscreened_urban <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + bmi_group + tobacco_smoked + tobacco_smokeless + d_id , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban))) 
screened_urban <- exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban)))
write.csv(screened_urban, "OR screened urbanmenpsu clusteringpoisson.csv")


CI_multiv_feclustscreened_urban <- confint(multiv_feclustscreened_urban)
write.csv(CI_multiv_feclustscreened_urban, "CI urban screenedmenpsu clusteringpoisson.csv")


#save(file="glm.clusterscreenedurban2018_03_22",multiv_feclustscreened_urban)
results_clustscreenedurban <-summary(multiv_feclustscreened_urban)
write.csv(results_clustscreenedurban, "resultsglmclustscreenedurban2018_03_22menpsu clusteringpoisson.csv")


#Rural aware
multiv_feclustaware_rural <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural))) 
aware_rural <- exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural)))
write.csv(aware_rural, "OR aware ruralmenpsu clusteringpoisson.csv")

CI_multiv_feclustaware_rural <- confint(multiv_feclustaware_rural)
write.csv(CI_multiv_feclustaware_rural, "CI rural awaremenpsu clusteringpoisson.csv")

#save(file="glm.clusterawarerural2018_03_22",multiv_feclustaware_rural)
results_clustawarerural <-summary(multiv_feclustaware_rural)
write.csv(results_clustawarerural, "resultsglmclustawarerural2018_03_22menpsu clusteringpoisson.csv")

#Urban aware
multiv_feclustaware_urban <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban))) 
aware_urban <- exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban)))
write.csv(aware_urban, "OR aware urbanmenpsu clusteringpoisson.csv")


CI_multiv_feclustaware_urban <- confint(multiv_feclustaware_urban)
write.csv(CI_multiv_feclustaware_urban, "CI urban awaremenpsu clusteringpoisson.csv")


#save(file="glm.clusterawareurban2018_03_22",multiv_feclustaware_urban)
results_clustawareurban <-summary(multiv_feclustaware_urban)
write.csv(results_clustawareurban, "resultsglmclustawareurban2018_03_22menpsu clusteringpoisson.csv")


#rural treated

multiv_feclusttreated_rural <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural)))
treated_rural <- exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural))) 
write.csv(treated_rural, "OR treated ruralmenpsu clusteringpoisson.csv")

CI_multiv_feclusttreated_rural <- confint(multiv_feclusttreated_rural)
write.csv(CI_multiv_feclusttreated_rural, "CI rural treatedmenpsu clusteringpoisson.csv")


#save(file="glm.clustertreatedrural2018_03_22",multiv_feclusttreated_rural)
results_clusttreatedrural <-summary(multiv_feclusttreated_rural)
write.csv(results_clusttreatedrural, "resultsglmclusttreatedrural2018_03_22menpsu clusteringpoisson.csv")

#urban treated

multiv_feclusttreated_urban <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban))) 
treated_urban <- exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban)))
write.csv(treated_urban, "OR treated urbanmenpsu clusteringpoisson.csv")

CI_multiv_feclusttreated_urban <- confint(multiv_feclusttreated_urban)
write.csv(CI_multiv_feclusttreated_urban, "CI urban treatedmenpsu clusteringpoisson.csv")


#save(file="glm.clustertreatedurban2018_03_22",multiv_feclusttreated_urban)
results_clusttreatedurban <-summary(multiv_feclusttreated_urban)
write.csv(results_clusttreatedurban, "resultsglmclusttreatedurban2018_03_22menpsu clusteringpoisson.csv")

#rural controlled


multiv_feclustcontrolled_rural <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
controlled_rural <- exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
write.csv(controlled_rural, "OR controlled ruralmenpsu clusteringpoisson.csv")

CI_multiv_feclustcontrolled_rural <- confint(multiv_feclustcontrolled_rural)
write.csv(CI_multiv_feclustcontrolled_rural, "CI rural controlledmenpsu clusteringpoisson.csv")


#save(file="glm.clustercontrolledrural2018_03_22",multiv_feclustcontrolled_rural)
results_clustcontrolledrural <-summary(multiv_feclustcontrolled_rural)
write.csv(results_clustcontrolledrural, "resultsglmclustcontrolledrural2018_03_22menpsu clusteringpoisson.csv")

#urban controlled

multiv_feclustcontrolled_urban <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
controlled_urban <- exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
write.csv(controlled_urban, "OR controlled urbanmenpsu clusteringpoisson.csv")

CI_multiv_feclustcontrolled_urban <- confint(multiv_feclustcontrolled_urban)
write.csv(CI_multiv_feclustcontrolled_urban, "CI urban controlledmenpsu clusteringpoisson.csv")

#save(file="glm.clustercontrolledurban2018_03_22",multiv_feclustcontrolled_urban)
results_clustcontrolledurban <-summary(multiv_feclustcontrolled_urban)
write.csv(results_clustcontrolledurban, "resultsglmclustcontrolledurban2018_03_22menpsu clusteringpoisson.csv")

```

```{r regression women only :psu clustering :urban vs. rural}

#PSU clustering, urban vs rural, Women#

#Rural screened
multiv_feclustscreened_rural <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural))) 
screened_rural <- exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural)))
write.csv(screened_rural, "OR screened ruralwomenpsu clusteringpoisson.csv")

CI_multiv_feclustscreened_rural <- confint(multiv_feclustscreened_rural)
write.csv(CI_multiv_feclustscreened_rural, "CI rural screenedwomenpsu clusteringpoisson.csv")

#save(file="glm.clusterscreenedrural2018_03_22",multiv_feclustscreened_rural)
results_clustscreenedrural <-summary(multiv_feclustscreened_rural)
write.csv(results_clustscreenedrural, "resultsglmclustscreenedrural2018_03_22womenpsu clusteringpoisson.csv")

#Urban screened
multiv_feclustscreened_urban <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + bmi_group + tobacco_smoked + tobacco_smokeless + d_id , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban))) 
screened_urban <- exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban)))
write.csv(screened_urban, "OR screened urbanwomenpsu clusteringpoisson.csv")


CI_multiv_feclustscreened_urban <- confint(multiv_feclustscreened_urban)
write.csv(CI_multiv_feclustscreened_urban, "CI urban screenedwomenpsu clusteringpoisson.csv")


#save(file="glm.clusterscreenedurban2018_03_22",multiv_feclustscreened_urban)
results_clustscreenedurban <-summary(multiv_feclustscreened_urban)
write.csv(results_clustscreenedurban, "resultsglmclustscreenedurban2018_03_22womenpsu clusteringpoisson.csv")


#Rural aware
multiv_feclustaware_rural <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural))) 
aware_rural <- exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural)))
write.csv(aware_rural, "OR aware ruralwomenpsu clusteringpoisson.csv")

CI_multiv_feclustaware_rural <- confint(multiv_feclustaware_rural)
write.csv(CI_multiv_feclustaware_rural, "CI rural awarewomenpsu clusteringpoisson.csv")

#save(file="glm.clusterawarerural2018_03_22",multiv_feclustaware_rural)
results_clustawarerural <-summary(multiv_feclustaware_rural)
write.csv(results_clustawarerural, "resultsglmclustawarerural2018_03_22womenpsu clusteringpoisson.csv")

#Urban aware
multiv_feclustaware_urban <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban))) 
aware_urban <- exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban)))
write.csv(aware_urban, "OR aware urbanwomenpsu clusteringpoisson.csv")


CI_multiv_feclustaware_urban <- confint(multiv_feclustaware_urban)
write.csv(CI_multiv_feclustaware_urban, "CI urban awarewomenpsu clusteringpoisson.csv")


#save(file="glm.clusterawareurban2018_03_22",multiv_feclustaware_urban)
results_clustawareurban <-summary(multiv_feclustaware_urban)
write.csv(results_clustawareurban, "resultsglmclustawareurban2018_03_22womenpsu clusteringpoisson.csv")


#rural treated

multiv_feclusttreated_rural <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural)))
treated_rural <- exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural))) 
write.csv(treated_rural, "OR treated ruralwomenpsu clusteringpoisson.csv")

CI_multiv_feclusttreated_rural <- confint(multiv_feclusttreated_rural)
write.csv(CI_multiv_feclusttreated_rural, "CI rural treatedwomenpsu clusteringpoisson.csv")


#save(file="glm.clustertreatedrural2018_03_22",multiv_feclusttreated_rural)
results_clusttreatedrural <-summary(multiv_feclusttreated_rural)
write.csv(results_clusttreatedrural, "resultsglmclusttreatedrural2018_03_22womenpsu clusteringpoisson.csv")

#urban treated

multiv_feclusttreated_urban <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban))) 
treated_urban <- exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban)))
write.csv(treated_urban, "OR treated urbanwomenpsu clusteringpoisson.csv")

CI_multiv_feclusttreated_urban <- confint(multiv_feclusttreated_urban)
write.csv(CI_multiv_feclusttreated_urban, "CI urban treatedwomenpsu clusteringpoisson.csv")


#save(file="glm.clustertreatedurban2018_03_22",multiv_feclusttreated_urban)
results_clusttreatedurban <-summary(multiv_feclusttreated_urban)
write.csv(results_clusttreatedurban, "resultsglmclusttreatedurban2018_03_22womenpsu clusteringpoisson.csv")

#rural controlled


multiv_feclustcontrolled_rural <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
controlled_rural <- exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
write.csv(controlled_rural, "OR controlled ruralwomenpsu clusteringpoisson.csv")

CI_multiv_feclustcontrolled_rural <- confint(multiv_feclustcontrolled_rural)
write.csv(CI_multiv_feclustcontrolled_rural, "CI rural controlledwomenpsu clusteringpoisson.csv")


#save(file="glm.clustercontrolledrural2018_03_22",multiv_feclustcontrolled_rural)
results_clustcontrolledrural <-summary(multiv_feclustcontrolled_rural)
write.csv(results_clustcontrolledrural, "resultsglmclustcontrolledrural2018_03_22womenpsu clusteringpoisson.csv")

#urban controlled

multiv_feclustcontrolled_urban <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married  + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
controlled_urban <- exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
write.csv(controlled_urban, "OR controlled urbanwomenpsu clusteringpoisson.csv")

CI_multiv_feclustcontrolled_urban <- confint(multiv_feclustcontrolled_urban)
write.csv(CI_multiv_feclustcontrolled_urban, "CI urban controlledwomenpsu clusteringpoisson.csv")

#save(file="glm.clustercontrolledurban2018_03_22",multiv_feclustcontrolled_urban)
results_clustcontrolledurban <-summary(multiv_feclustcontrolled_urban)
write.csv(results_clustcontrolledurban, "resultsglmclustcontrolledurban2018_03_22womenpsu clusteringpoisson.csv")


```

```{r regressions no  clustering : WEIGHTS urban vs rural}

#clustered regressions for urban and rural separately, no FE  WITH WEIGHTS#


#Rural htn

#multiv_feclust_htn_rural <- glm(formula = ex_htn_broad_ind ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_rural, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_rural), confint.default(multiv_feclust_htn_rural))) 
#htn_rural <- exp(cbind(OR = coef(multiv_feclust_htn_rural), confint.default(multiv_feclust_htn_rural))) 
#write.csv(htn_rural, "OR htn ruralwithweightspoisson.csv")

#CI_multiv_feclust_htn_rural <- confint(multiv_feclust_htn_rural)
#write.csv(CI_multiv_feclust_htn_rural, "CI rural htnwithweightspoisson.csv")



#save(file="glm.clusthtnrural2018_03_22",multiv_feclust_htn_rural)
#results_clusthtnrural <-summary(multiv_feclust_htn_rural)


#results_clusthtnrural_CI <- as.data.frame(results_clusthtnrural)

#write.csv(results_clusthtnrural, "resultsglmclusthtnrural2018_03_22withweightspoisson.csv")

#Urban htn

#multiv_feclust_htn_urban <- glm(formula = ex_htn_broad_ind ~  age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#htn_urban <- exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#write.csv(htn_urban, "OR htn urbanwithweightspoisson.csv")


#CI_multiv_feclust_htn_urban <- confint(multiv_feclust_htn_urban)
#write.csv(CI_multiv_feclust_htn_urban, "CI urban htnwithweightspoisson.csv")




#save(file="glm.clusthtnurban2018_03_22",multiv_feclust_htn_urban)
#results_clusthtnurban <-summary(multiv_feclust_htn_urban)
#write.csv(results_clusthtnurban, "resultsglmclusthtnurban2018_03_22withweightspoisson.csv")

#Rural screened
multiv_feclustscreened_rural <- glm(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclustscreened_rural), confint(multiv_feclustscreened_rural))) 
screened_rural <- exp(cbind(OR = coef(multiv_feclustscreened_rural), confint.default(multiv_feclustscreened_rural)))
write.csv(screened_rural, "OR screened ruralwithweightspoisson.csv")



#save(file="glmscreenedrural2018_03_22",multiv_feclustscreened_rural)
results_clustscreenedrural <-summary(multiv_feclustscreened_rural)$coefficients
write.csv(results_clustscreenedrural, "resultsglmclustscreenedrural2018_03_22withweightspoisson.csv")

#Urban screened
multiv_feclustscreened_urban <- glm(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclustscreened_urban), confint(multiv_feclustscreened_urban))) 
screened_urban <- exp(cbind(OR = coef(multiv_feclustscreened_urban), confint.default(multiv_feclustscreened_urban)))
write.csv(screened_urban, "OR screened urbanwithweightspoisson.csv")





#save(file="glmscreenedurban2018_03_22",multiv_feclustscreened_urban)
results_clustscreenedurban <-summary(multiv_feclustscreened_urban)$coefficients
write.csv(results_clustscreenedurban, "resultsglmclustscreenedurban2018_03_22withweightspoisson.csv")


#Rural aware
multiv_feclustaware_rural <- glm(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclustaware_rural), confint(multiv_feclustaware_rural))) 
aware_rural <- exp(cbind(OR = coef(multiv_feclustaware_rural), confint.default(multiv_feclustaware_rural)))
write.csv(aware_rural, "OR aware ruralwithweightspoisson.csv")



#save(file="glmawarerural2018_03_22",multiv_feclustaware_rural)
results_clustawarerural <-summary(multiv_feclustaware_rural)$coefficients
write.csv(results_clustawarerural, "resultsglmclustawarerural2018_03_22withweightspoisson.csv")

#Urban aware
multiv_feclustaware_urban <- glm(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclustaware_urban), confint(multiv_feclustaware_urban))) 
aware_urban <- exp(cbind(OR = coef(multiv_feclustaware_urban), confint.default(multiv_feclustaware_urban)))
write.csv(aware_urban, "OR aware urbanwithweightspoisson.csv")



#save(file="glmawareurban2018_03_22",multiv_feclustaware_urban)
results_clustawareurban <-summary(multiv_feclustaware_urban)$coefficients
write.csv(results_clustawareurban, "resultsglmclustawareurban2018_03_22withweightspoisson.csv")


#rural treated

multiv_feclusttreated_rural <- glm(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclusttreated_rural), confint(multiv_feclusttreated_rural)))
treated_rural <- exp(cbind(OR = coef(multiv_feclusttreated_rural), confint.default(multiv_feclusttreated_rural))) 
write.csv(treated_rural, "OR treated ruralwithweightspoisson.csv")

#save(file="glmtreatedrural2018_03_22",multiv_feclusttreated_rural)
results_clusttreatedrural <-summary(multiv_feclusttreated_rural)$coefficients
write.csv(results_clusttreatedrural, "resultsglmclusttreatedrural2018_03_22withweightspoisson.csv")

#urban treated

multiv_feclusttreated_urban <- glm(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclusttreated_urban), confint(multiv_feclusttreated_urban))) 
treated_urban <- exp(cbind(OR = coef(multiv_feclusttreated_urban), confint.default(multiv_feclusttreated_urban)))
write.csv(treated_urban, "OR treated urbanwithweightspoisson.csv")

#save(file="glmtreatedurban2018_03_22",multiv_feclusttreated_urban)
results_clusttreatedurban <-summary(multiv_feclusttreated_urban)$coefficients
write.csv(results_clusttreatedurban, "resultsglmclusttreatedurban2018_03_22withweightspoisson.csv")

#rural controlled


multiv_feclustcontrolled_rural <- glm(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint(multiv_feclustcontrolled_rural))) 
controlled_rural <- exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint.default(multiv_feclustcontrolled_rural))) 
write.csv(controlled_rural, "OR controlled ruralwithweightspoisson.csv")


#save(file="glmcontrolledrural2018_03_22",multiv_feclustcontrolled_rural)
results_clustcontrolledrural <-summary(multiv_feclustcontrolled_rural)$coefficients
write.csv(results_clustcontrolledrural, "resultsglmclustcontrolledrural2018_03_22withweightspoisson.csv")

#urban controlled

multiv_feclustcontrolled_urban <- glm(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint(multiv_feclustcontrolled_urban)))
controlled_urban <- exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint.default(multiv_feclustcontrolled_urban)))
write.csv(controlled_urban, "OR controlled urbanwithweightspoisson.csv")


#save(file="glmcontrolledurban2018_03_22",multiv_feclustcontrolled_urban)
results_clustcontrolledurban <-summary(multiv_feclustcontrolled_urban)$coefficients
write.csv(results_clustcontrolledurban, "resultsglmclustcontrolledurban2018_03_22withweightspoisson.csv")


```

```{r regression psu clustering: FE :interaction married and sex}

#clustered regressions for urban and rural separately,  PSU-Clustering, Interaction term married and sex#


#Rural htn

#multiv_feclust_htn_rural <- glm.cluster(formula = ex_htn_broad_ind ~ age_grp2 + wealth_quintile_rurb + educatnames #+ married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", #data=dhs_nomiss_rural, family=poisson(link="log"))
#htn_rural <- exp(cbind(OR = coef(multiv_feclust_htn_rural), confint.default(multiv_feclust_htn_rural))) 
#write.csv(htn_rural, "OR htn ruralwith interaction term sex_and_marriedpoisson.csv")

#CI_multiv_feclust_htn_rural <- confint(multiv_feclust_htn_rural)
#write.csv(CI_multiv_feclust_htn_rural, "CI rural htnwith interaction term sex_and_marriedpoisson.csv")



#save(file="glm.clusthtnrural2018_03_22",multiv_feclust_htn_rural)
#results_clusthtnrural <-summary(multiv_feclust_htn_rural)$coefficients

#write.csv(results_clusthtnrural, "resultsglmclusthtnrural2018_03_22with interaction term sex_and_marriedpoisson.csv")

#Urban htn

#multiv_feclust_htn_urban <- glm.cluster(formula = ex_htn_broad_ind ~  age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_urban, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#htn_urban <- exp(cbind(OR = coef(multiv_feclust_htn_urban), confint(multiv_feclust_htn_urban))) 
#write.csv(htn_urban, "OR htn urbanwith interaction term sex_and_marriedpoisson.csv")


#CI_multiv_feclust_htn_urban <- confint(multiv_feclust_htn_urban)
#write.csv(CI_multiv_feclust_htn_urban, "CI urban htnwith interaction term sex_and_marriedpoisson.csv")




#save(file="glm.clusthtnurban2018_03_22",multiv_feclust_htn_urban)
#results_clusthtnurban <-summary(multiv_feclust_htn_urban)
#write.csv(results_clusthtnurban, "resultsglmclusthtnurban2018_03_22with interaction term sex_and_marriedpoisson.csv")

#Rural screened
multiv_feclustscreened_rural <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
screened_rural <- exp(cbind(OR = coef(multiv_feclustscreened_rural), confint.default(multiv_feclustscreened_rural)))
write.csv(screened_rural, "OR screened ruralwith interaction term sex_and_marriedpoisson.csv")


#save(file="glm.clusterscreenedrural2018_03_22",multiv_feclustscreened_rural)
results_clustscreenedrural <-summary(multiv_feclustscreened_rural)
write.csv(results_clustscreenedrural, "resultsglmclustscreenedrural2018_03_22with interaction term sex_and_marriedpoisson.csv")

#Urban screened
multiv_feclustscreened_urban <- glm.cluster(formula = htn_screened_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
screened_urban <- exp(cbind(OR = coef(multiv_feclustscreened_urban), confint.default(multiv_feclustscreened_urban)))
write.csv(screened_urban, "OR screened urbanwith interaction term sex_and_marriedpoisson.csv")



#save(file="glm.clusterscreenedurban2018_03_22",multiv_feclustscreened_urban)
results_clustscreenedurban <-summary(multiv_feclustscreened_urban)
write.csv(results_clustscreenedurban, "resultsglmclustscreenedurban2018_03_22with interaction term sex_and_marriedpoisson.csv")


#Rural aware
multiv_feclustaware_rural <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
aware_rural <- exp(cbind(OR = coef(multiv_feclustaware_rural), confint.default(multiv_feclustaware_rural)))
write.csv(aware_rural, "OR aware ruralwith interaction term sex_and_marriedpoisson.csv")

#save(file="glm.clusterawarerural2018_03_22",multiv_feclustaware_rural)
results_clustawarerural <-summary(multiv_feclustaware_rural)
write.csv(results_clustawarerural, "resultsglmclustawarerural2018_03_22with interaction term sex_and_marriedpoisson.csv")

#Urban aware
multiv_feclustaware_urban <- glm.cluster(formula = htn_aware_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
aware_urban <- exp(cbind(OR = coef(multiv_feclustaware_urban), confint.default(multiv_feclustaware_urban)))
write.csv(aware_urban, "OR aware urbanwith interaction term sex_and_marriedpoisson.csv")


#save(file="glm.clusterawareurban2018_03_22",multiv_feclustaware_urban)
results_clustawareurban <-summary(multiv_feclustaware_urban)
write.csv(results_clustawareurban, "resultsglmclustawareurban2018_03_22with interaction term sex_and_marriedpoisson.csv")


#rural treated

multiv_feclusttreated_rural <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
treated_rural <- exp(cbind(OR = coef(multiv_feclusttreated_rural), confint.default(multiv_feclusttreated_rural))) 
write.csv(treated_rural, "OR treated ruralwith interaction term sex_and_marriedpoisson.csv")

#save(file="glm.clustertreatedrural2018_03_22",multiv_feclusttreated_rural)
results_clusttreatedrural <-summary(multiv_feclusttreated_rural)
write.csv(results_clusttreatedrural, "resultsglmclusttreatedrural2018_03_22with interaction term sex_and_marriedpoisson.csv")

#urban treated

multiv_feclusttreated_urban <- glm.cluster(formula = htn_treated_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married +sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
treated_urban <- exp(cbind(OR = coef(multiv_feclusttreated_urban), confint.default(multiv_feclusttreated_urban)))
write.csv(treated_urban, "OR treated urbanwith interaction term sex_and_marriedpoisson.csv")


#save(file="glm.clustertreatedurban2018_03_22",multiv_feclusttreated_urban)
results_clusttreatedurban <-summary(multiv_feclusttreated_urban)
write.csv(results_clusttreatedurban, "resultsglmclusttreatedurban2018_03_22with interaction term sex_and_marriedpoisson.csv")

#rural controlled


multiv_feclustcontrolled_rural <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
controlled_rural <- exp(cbind(OR = coef(multiv_feclustcontrolled_rural), confint.default(multiv_feclustcontrolled_rural))) 
write.csv(controlled_rural, "OR controlled ruralwith interaction term sex_and_marriedpoisson.csv")


#save(file="glm.clustercontrolledrural2018_03_22",multiv_feclustcontrolled_rural)
results_clustcontrolledrural <-summary(multiv_feclustcontrolled_rural)
write.csv(results_clustcontrolledrural, "resultsglmclustcontrolledrural2018_03_22with interaction term sex_and_marriedpoisson.csv")

#urban controlled

multiv_feclustcontrolled_urban <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2 + wealth_quintile_rurb + educatnames + married + sex + bmi_group + tobacco_smoked + tobacco_smokeless + d_id + sex:married  , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
controlled_urban <- exp(cbind(OR = coef(multiv_feclustcontrolled_urban), confint.default(multiv_feclustcontrolled_urban)))
write.csv(controlled_urban, "OR controlled urbanwith interaction term sex_and_marriedpoisson.csv")

#save(file="glm.clustercontrolledurban2018_03_22",multiv_feclustcontrolled_urban)
results_clustcontrolledurban <-summary(multiv_feclustcontrolled_urban)
write.csv(results_clustcontrolledurban, "resultsglmclustcontrolledurban2018_03_22with interaction term sex_and_marriedpoisson.csv")

```


```{r creating subsample for spline regressions}

dhs_nomiss_spline <- dhs_nomiss_htn_only
#dhs_nomiss_spline_test<-dhs_nomiss_spline %>% group_by(d_id,urban_lab) %>% sample_frac(.1)


dhs_nomiss_spline_rural <- filter(dhs_nomiss_spline, urban_lab=="Rural")
dhs_nomiss_spline_urban <- filter(dhs_nomiss_spline, urban_lab=="Urban")


```


```{r spline regressions with 5 knots poisson}

#rural

multiv_feclust_screened_htn_rural555 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_screened_htn_rural555), confint.default(multiv_feclust_screened_htn_rural555))) 
htn_rural <- exp(cbind(OR = coef(multiv_feclust_screened_htn_rural555), confint.default(multiv_feclust_screened_htn_rural555))) 
write.csv(htn_rural, "OR spline screened 555 ruralpoisson.csv")

CI_multiv_feclust_screened_htn_rural555 <- confint.default(multiv_feclust_screened_htn_rural555)
write.csv(CI_multiv_feclust_screened_htn_rural555, "CI spline screened 555 ruralpoisson.csv")




multiv_feclust_aware_htn_rural555 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_aware_htn_rural555), confint.default(multiv_feclust_aware_htn_rural555))) 
htn_rural <- exp(cbind(OR = coef(multiv_feclust_aware_htn_rural555), confint.default(multiv_feclust_aware_htn_rural555))) 
write.csv(htn_rural, "OR spline aware 555 ruralpoisson.csv")

CI_multiv_feclust_aware_htn_rural555 <- confint.default(multiv_feclust_aware_htn_rural555)
write.csv(CI_multiv_feclust_aware_htn_rural555, "CI spline aware 555 ruralpoisson.csv")



multiv_feclust_treated_htn_rural555 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_treated_htn_rural555), confint.default(multiv_feclust_treated_htn_rural555))) 
htn_rural <- exp(cbind(OR = coef(multiv_feclust_treated_htn_rural555), confint.default(multiv_feclust_treated_htn_rural555))) 
write.csv(htn_rural, "OR spline treated 555 ruralpoisson.csv")

CI_multiv_feclust_treated_htn_rural555 <- confint.default(multiv_feclust_treated_htn_rural555)
write.csv(CI_multiv_feclust_treated_htn_rural555, "CI spline treated 555 ruralpoisson.csv")



multiv_feclust_controlled_htn_rural555 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_controlled_htn_rural555), confint.default(multiv_feclust_controlled_htn_rural555))) 
htn_rural <- exp(cbind(OR = coef(multiv_feclust_controlled_htn_rural555), confint.default(multiv_feclust_controlled_htn_rural555))) 
write.csv(htn_rural, "OR spline controlled 555 ruralpoisson.csv")

CI_multiv_feclust_controlled_htn_rural555 <- confint.default(multiv_feclust_controlled_htn_rural555)
write.csv(CI_multiv_feclust_controlled_htn_rural555, "CI spline controlled 555 ruralpoisson.csv")


#urban

multiv_feclust_screened_htn_urban555 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_screened_htn_urban555), confint.default(multiv_feclust_screened_htn_urban555))) 
htn_urban <- exp(cbind(OR = coef(multiv_feclust_screened_htn_urban555), confint.default(multiv_feclust_screened_htn_urban555))) 
write.csv(htn_urban, "OR spline screened 555 urbanpoisson.csv")

CI_multiv_feclust_screened_htn_urban555 <- confint.default(multiv_feclust_screened_htn_urban555)
write.csv(CI_multiv_feclust_screened_htn_urban555, "CI spline screened 555 urbanpoisson.csv")

multiv_feclust_aware_htn_urban555 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_aware_htn_urban555), confint.default(multiv_feclust_aware_htn_urban555))) 
htn_urban <- exp(cbind(OR = coef(multiv_feclust_aware_htn_urban555), confint.default(multiv_feclust_aware_htn_urban555))) 
write.csv(htn_urban, "OR spline aware 555 urbanpoisson.csv")

CI_multiv_feclust_aware_htn_urban555 <- confint.default(multiv_feclust_aware_htn_urban555)
write.csv(CI_multiv_feclust_aware_htn_urban555, "CI spline aware 555 urbanpoisson.csv")

multiv_feclust_treated_htn_urban555 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_treated_htn_urban555), confint.default(multiv_feclust_treated_htn_urban555))) 
htn_urban <- exp(cbind(OR = coef(multiv_feclust_treated_htn_urban555), confint.default(multiv_feclust_treated_htn_urban555))) 
write.csv(htn_urban, "OR spline treated 555 urbanpoisson.csv")

CI_multiv_feclust_treated_htn_urban555 <- confint.default(multiv_feclust_treated_htn_urban555)
write.csv(CI_multiv_feclust_treated_htn_urban555, "CI spline treated 555 urbanpoisson.csv")

multiv_feclust_controlled_htn_urban555 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_controlled_htn_urban555), confint.default(multiv_feclust_controlled_htn_urban555))) 
htn_urban <- exp(cbind(OR = coef(multiv_feclust_controlled_htn_urban555), confint.default(multiv_feclust_controlled_htn_urban555))) 
write.csv(htn_urban, "OR spline controlled 555 urbanpoisson.csv")

CI_multiv_feclust_controlled_htn_urban555 <- confint.default(multiv_feclust_controlled_htn_urban555)
write.csv(CI_multiv_feclust_controlled_htn_urban555, "CI spline controlled 555 urbanpoisson.csv")






```


```{r spline regressions with 5 knots for Regression table POISSON}


#RURAL

multiv_feclust_screened_htnruralnoweights <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,    data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))



exp(cbind(OR = coef(multiv_feclust_screened_htnruralnoweights), confint.default(multiv_feclust_screened_htnruralnoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_screened_htnruralnoweights), confint.default(multiv_feclust_screened_htnruralnoweights))) 
write.csv(htn, "OR spline screened ruralnoweights urbanpoissonforregressiontablerural.csv")

results_multiv_feclust_screened_htnruralnoweights <-summary(multiv_feclust_screened_htnruralnoweights)$coefficients
write.csv(results_multiv_feclust_screened_htnruralnoweights, "spline screened rural poisson regression table.csv")



multiv_feclust_aware_htnruralnoweights <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_aware_htnruralnoweights), confint.default(multiv_feclust_aware_htnruralnoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_aware_htnruralnoweights), confint.default(multiv_feclust_aware_htnruralnoweights))) 
write.csv(htn, "OR spline aware ruralnoweights urbanpoissonforregressiontablerural.csv")

results_multiv_feclust_aware_htnruralnoweights <-summary(multiv_feclust_aware_htnruralnoweights)$coefficients
write.csv(results_multiv_feclust_aware_htnruralnoweights, "spline aware rural poisson regression table.csv")


multiv_feclust_treated_htnruralnoweights <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_treated_htnruralnoweights), confint.default(multiv_feclust_treated_htnruralnoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_treated_htnruralnoweights), confint.default(multiv_feclust_treated_htnruralnoweights))) 
write.csv(htn, "OR spline treated ruralnoweights urbanpoissonforregressiontablerural.csv")

results_multiv_feclust_treated_htnruralnoweights <-summary(multiv_feclust_treated_htnruralnoweights)$coefficients
write.csv(results_multiv_feclust_treated_htnruralnoweights, "spline treated rural poisson regression table.csv")


multiv_feclust_controlled_htnruralnoweights <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))


exp(cbind(OR = coef(multiv_feclust_controlled_htnruralnoweights), confint.default(multiv_feclust_controlled_htnruralnoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_controlled_htnruralnoweights), confint.default(multiv_feclust_controlled_htnruralnoweights))) 
write.csv(htn, "OR spline controlled ruralnoweights urbanpoissonforregressiontablerural.csv")

results_multiv_feclust_controlled_htnruralnoweights <-summary(multiv_feclust_controlled_htnruralnoweights)$coefficients
write.csv(results_multiv_feclust_controlled_htnruralnoweights, "spline controlled rural poisson regression table.csv")




#urban

multiv_feclust_screened_htnurbannoweights <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,    data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))



exp(cbind(OR = coef(multiv_feclust_screened_htnurbannoweights), confint.default(multiv_feclust_screened_htnurbannoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_screened_htnurbannoweights), confint.default(multiv_feclust_screened_htnurbannoweights))) 
write.csv(htn, "OR spline screened urbannoweights urbanpoissonforregressiontableurban.csv")

results_multiv_feclust_screened_htnurbannoweights <-summary(multiv_feclust_screened_htnurbannoweights)$coefficients
write.csv(results_multiv_feclust_screened_htnurbannoweights, "spline screened urban poisson regression table.csv")




multiv_feclust_aware_htnurbannoweights <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_aware_htnurbannoweights), confint.default(multiv_feclust_aware_htnurbannoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_aware_htnurbannoweights), confint.default(multiv_feclust_aware_htnurbannoweights))) 
write.csv(htn, "OR spline aware urbannoweights urbanpoissonforregressiontableurban.csv")

results_multiv_feclust_aware_htnurbannoweights <-summary(multiv_feclust_aware_htnurbannoweights)$coefficients
write.csv(results_multiv_feclust_aware_htnurbannoweights, "spline aware urban poisson regression table.csv")


multiv_feclust_treated_htnurbannoweights <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))

exp(cbind(OR = coef(multiv_feclust_treated_htnurbannoweights), confint.default(multiv_feclust_treated_htnurbannoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_treated_htnurbannoweights), confint.default(multiv_feclust_treated_htnurbannoweights))) 
write.csv(htn, "OR spline treated urbannoweights urbanpoissonforregressiontableurban.csv")

results_multiv_feclust_treated_htnurbannoweights <-summary(multiv_feclust_treated_htnurbannoweights)$coefficients
write.csv(results_multiv_feclust_treated_htnurbannoweights, "spline treated urban poisson regression table.csv")


multiv_feclust_controlled_htnurbannoweights <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))


exp(cbind(OR = coef(multiv_feclust_controlled_htnurbannoweights), confint.default(multiv_feclust_controlled_htnurbannoweights))) 
htn <- exp(cbind(OR = coef(multiv_feclust_controlled_htnurbannoweights), confint.default(multiv_feclust_controlled_htnurbannoweights))) 
write.csv(htn, "OR spline controlled urbannoweights urbanpoissonforregressiontableurban.csv")

results_multiv_feclust_controlled_htnurbannoweights <-summary(multiv_feclust_controlled_htnurbannoweights)$coefficients
write.csv(results_multiv_feclust_controlled_htnurbannoweights, "spline controlled urban poisson regression table.csv")









```





```{r spline regressions with 5 knots for PREDICTED PROBABILITY FIGURE NO WEIGHTS}




multiv_feclust_screened_htn555noweights <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,    data=dhs_nomiss_htn_only, family=binomial(link="logit"))





multiv_feclust_aware_htn555noweights <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))




multiv_feclust_treated_htn555noweights <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))




multiv_feclust_controlled_htn555noweights <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))











```

```{r spline regressions with 5 knots for PREDICTED PROBABILITY FIGURE WEIGHTS}




multiv_feclust_screened_htn555 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,  weights= p_wt_new,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))





multiv_feclust_aware_htn555 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))




multiv_feclust_treated_htn555 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))




multiv_feclust_controlled_htn555 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))











```






```{r spline regressions with 5 knots for PREDICTED PROBABILITY FIGURE Women only}




multiv_feclust_screened_htn555women <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))





multiv_feclust_aware_htn555women <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))




multiv_feclust_treated_htn555women <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))




multiv_feclust_controlled_htn555women <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_women, family=binomial(link="logit"))











```





```{r spline regressions with 5 knots for PREDICTED PROBABILITY FIGURE men only}




multiv_feclust_screened_htn555men <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_men, family=binomial(link="logit"))





multiv_feclust_aware_htn555men <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_men, family=binomial(link="logit"))




multiv_feclust_treated_htn555men <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_men, family=binomial(link="logit"))




multiv_feclust_controlled_htn555men <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  weights= p_wt_new,  data=dhs_nomiss_htn_only_men, family=binomial(link="logit"))











```


```{r regressions for new spline figure}

multiv_feclust_screened_htn555noweights <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban ,    data=dhs_nomiss_htn_only, family=binomial(link="logit"))


multiv_feclust_aware_htn555noweights <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))




multiv_feclust_treated_htn555noweights <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))




multiv_feclust_controlled_htn555noweights <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban  ,  data=dhs_nomiss_htn_only, family=binomial(link="logit"))


#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_feclust_screened_htn555noweights, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_screened = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_feclust_aware_htn555noweights, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_aware = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


#Regression figure for treated wealth quintile#

dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_feclust_treated_htn555noweights, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_treated = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)

#Regression figure for controlled wealth quintile#

dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_feclust_controlled_htn555noweights, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_controlled = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)



```


```{r new spline figure age}




# Create dataset for plotting
pmeans_htn <- aggregate(prob_screened ~ age, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
figscreened.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age"))
figscreened.htn <- mutate(figscreened.htn, 
                   lowerci = prob_screened-(1.96*se_htn),
                   upperci = prob_screened+(1.96*se_htn))


write.csv(figscreened.htn, "regressionfigure_screened_wealth htn SIMPLE.csv")





# Create dataset for plotting
pmeans_htn <- aggregate(prob_aware ~ age, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
figaware.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age"))
figaware.htn <- mutate(figaware.htn, 
                   lowerci = prob_aware-(1.96*se_htn),
                   upperci = prob_aware+(1.96*se_htn))


write.csv(figaware.htn, "regressionfigure_aware_wealth htn SIMPLE.csv")





# Create dataset for plotting
pmeans_htn <- aggregate(prob_treated ~ age, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
figtreated.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age"))
figtreated.htn <- mutate(figtreated.htn, 
                   lowerci = prob_treated-(1.96*se_htn),
                   upperci = prob_treated+(1.96*se_htn))


write.csv(figtreated.htn, "regressionfigure_treated_wealth htn SIMPLE.csv")




# Create dataset for plotting
pmeans_htn <- aggregate(prob_controlled ~ age, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
figcontrolled.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age"))
figcontrolled.htn <- mutate(figcontrolled.htn, 
                   lowerci = prob_controlled-(1.96*se_htn),
                   upperci = prob_controlled+(1.96*se_htn))


write.csv(figcontrolled.htn, "regressionfigure_controlled_wealth htn SIMPLE.csv")



figscreenedfinal.htn <- left_join(figscreened.htn, figaware.htn, by = c("age"))
figscreenedfinal.htn <- left_join(figscreenedfinal.htn, figtreated.htn, by = c("age"))
figscreenedfinal.htn <- left_join(figscreenedfinal.htn, figcontrolled.htn, by = c("age"))

figscreenedfinal.htn <- mutate(figscreenedfinal.htn, 
                              prob_screened = prob_screened*100,
                              prob_aware = prob_aware*100,
                              prob_treated = prob_treated*100,
                   prob_controlled = prob_controlled*100)

count <- c(890,1103,1164,1579,1490,2044,1781,2421,2469,2617,3603,2869,2964,3847,2846,5390,2891,4362,3339,3356,6501,4090,3847,5116,3828,7724,3548,5202,4114,3792,8555,4379,4420,5825,4295)

figscreenedfinal.htn <-cbind(figscreenedfinal.htn,count)



                   





#####Screened 
stateawarefig <- figscreenedfinal.htn %>% 
    ggplot()+
  geom_bar(aes(x = age, y = count/200), stat = "identity",  alpha=0.7,width=1)+
  #     geom_histogram(aes(x=age, y=(count)), binwidth=0.1, alpha=0.7) +
  geom_smooth(aes(y=prob_screened, x=age),method='loess', se= FALSE, color="blue") +
  
 #  geom_point(aes(y=prob_screened, x=age), size=2.5, color="blue") +
      geom_smooth(aes(y=prob_aware, x=age),method='loess', se= FALSE, color="red") +
 #  geom_point(aes(y=prob_aware, x=age), size=2.5, color="red") +
     geom_smooth(aes(y=prob_treated, x=age),method='loess', se= FALSE, color="orange") +
#   geom_point(aes(y=prob_treated, x=age), size=2.5, color="orange") +
      geom_smooth(aes(y=prob_controlled, x=age),method='loess', se= FALSE, color="purple") +
 #  geom_point(aes(y=prob_controlled, x=age), size=2.5, color="purple") +
  theme_classic() + 
  labs(x = "age (years)",
       y = " Percentage",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(20, 40,60,80,100), limits=c(0, 100)) +
  scale_x_continuous(breaks = c(15,20,30,40,49), limits=c(15, 49)) +
  coord_fixed(34/100, expand=F)
stateawarefig


  
  
  
  
  #  geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$prob_screened ~ figscreenedfinal.htn$age,span=1)),x=age), alpha = 1, fill = "firebrick1") +
#    geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$prob_aware ~ figscreenedfinal.htn$age,span=1)),x=age), alpha = 1, fill = "darkorange1") +
#    geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$prob_treated ~ figscreenedfinal.htn$age,span=1)),x=age), alpha = 1, fill = "darkviolet") +
#    geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$prob_controlled ~ figscreenedfinal.htn$age,span=1)),x=age), alpha = 1, fill = "gray23") +
#  geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$twomorb ~ figscreenedfinal.htn$age,span=1)),x=$age), alpha = 1, fill = "firebrick3") +
#  geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$threemorb ~ figscreenedfinal.htn$age,span=1)),x=age), alpha = 1, fill = "firebrick4") +
 # geom_ribbon(aes(ymin = 0, ymax = predict(loess(figscreenedfinal.htn$fourmorb ~ figscreenedfinal.htn$age,span=1)),x=age), alpha = 1, fill = "gray23") +
  
  
  
  
  

  ggplot(aes(y=htn_screened_dbl, x=age)) +
  geom_smooth(method='glm', formula= htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex +urban + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id + asset_index:age + asset_index:urban + age:urban, se= FALSE, color="black") +
  geom_jitter(aes(y=htn_screened_dbl, x=age), size=2.5) +
  theme_classic() + 
  labs(x = "Screened, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateawarefig




```



```{r new spline figure household wealth}




# Create dataset for plotting
pmeans_htn <- aggregate(prob_screened ~ asset_index, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ asset_index, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
figscreened.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("asset_index"))
figscreened.htn <- mutate(figscreened.htn, 
                   lowerci = prob_screened-(1.96*se_htn),
                   upperci = prob_screened+(1.96*se_htn))


write.csv(figscreened.htn, "regressionfigure_screened_wealth htn SIMPLEasset_index.csv")





# Create dataset for plotting
pmeans_htn <- aggregate(prob_aware ~ asset_index, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ asset_index, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
figaware.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("asset_index"))
figaware.htn <- mutate(figaware.htn, 
                   lowerci = prob_aware-(1.96*se_htn),
                   upperci = prob_aware+(1.96*se_htn))


write.csv(figaware.htn, "regressionfigure_aware_wealth htn SIMPLEasset_index.csv")





# Create dataset for plotting
pmeans_htn <- aggregate(prob_treated ~ asset_index, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ asset_index, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
figtreated.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("asset_index"))
figtreated.htn <- mutate(figtreated.htn, 
                   lowerci = prob_treated-(1.96*se_htn),
                   upperci = prob_treated+(1.96*se_htn))


write.csv(figtreated.htn, "regressionfigure_treated_wealth htn SIMPLEasset_index.csv")




# Create dataset for plotting
pmeans_htn <- aggregate(prob_controlled ~ asset_index, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ asset_index, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
figcontrolled.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("asset_index"))
figcontrolled.htn <- mutate(figcontrolled.htn, 
                   lowerci = prob_controlled-(1.96*se_htn),
                   upperci = prob_controlled+(1.96*se_htn))


write.csv(figcontrolled.htn, "regressionfigure_controlled_wealth htn SIMPLEasset_index.csv")



figscreenedfinal.htn <- left_join(figscreened.htn, figaware.htn, by = c("asset_index"))
figscreenedfinal.htn <- left_join(figscreenedfinal.htn, figtreated.htn, by = c("asset_index"))
figscreenedfinal.htn <- left_join(figscreenedfinal.htn, figcontrolled.htn, by = c("asset_index"))

figscreenedfinal.htn <- mutate(figscreenedfinal.htn, 
                              prob_screened = prob_screened*100,
                              prob_aware = prob_aware*100,
                              prob_treated = prob_treated*100,
                   prob_controlled = prob_controlled*100)
                   




#####Screened 
stateawarefig <- figscreenedfinal.htn %>% 
    ggplot()+
     geom_histogram(aes(x=asset_index, y=(..ncount..)*20), stat="bin", binwidth=0.1, alpha=0.7) +
 #  geom_point(aes(y=prob_screened, x=asset_index), size=0.01, color="cyan") +
    geom_smooth(aes(y=prob_screened, x=asset_index),method='loess', se= FALSE, color="blue") +
 #  geom_point(aes(y=prob_aware, x=asset_index), size=0.01, color="coral") +
      geom_smooth(aes(y=prob_aware, x=asset_index),method='loess', se= FALSE, color="red") +
#   geom_point(aes(y=prob_treated, x=asset_index), size=0.01, color="darkgoldenrod1") +
      geom_smooth(aes(y=prob_treated, x=asset_index),method='loess', se= FALSE, color="orange") +
#   geom_point(aes(y=prob_controlled, x=asset_index), size=0.01, color="darkmagenta") +
      geom_smooth(aes(y=prob_controlled, x=asset_index),method='loess', se= FALSE, color="purple") +
 # geom_histogram(aes(x=asset_index, y=(..ncount..)/4.5), stat="bin")
  theme_classic() + 
  labs(x = "Household wealth index",
       y = " Percentage",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(20, 40,60,80,100), limits=c(0, 100)) +
  scale_x_continuous(breaks = c(-2,-1,0,1,2,2.7), limits=c(-2, 2.7)) +
  coord_fixed(4.7/100, expand=F)
stateawarefig


```



```{r new spline figure bmi}




# Create dataset for plotting
pmeans_htn <- aggregate(prob_screened ~ bmi, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ bmi, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
figscreened.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("bmi"))
figscreened.htn <- mutate(figscreened.htn, 
                   lowerci = prob_screened-(1.96*se_htn),
                   upperci = prob_screened+(1.96*se_htn))


write.csv(figscreened.htn, "regressionfigure_screened_wealth htn SIMPLEbmi.csv")





# Create dataset for plotting
pmeans_htn <- aggregate(prob_aware ~ bmi, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ bmi, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
figaware.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("bmi"))
figaware.htn <- mutate(figaware.htn, 
                   lowerci = prob_aware-(1.96*se_htn),
                   upperci = prob_aware+(1.96*se_htn))


write.csv(figaware.htn, "regressionfigure_aware_wealth htn SIMPLEbmi.csv")





# Create dataset for plotting
pmeans_htn <- aggregate(prob_treated ~ bmi, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ bmi, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
figtreated.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("bmi"))
figtreated.htn <- mutate(figtreated.htn, 
                   lowerci = prob_treated-(1.96*se_htn),
                   upperci = prob_treated+(1.96*se_htn))


write.csv(figtreated.htn, "regressionfigure_treated_wealth htn SIMPLEbmi.csv")




# Create dataset for plotting
pmeans_htn <- aggregate(prob_controlled ~ bmi, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ bmi, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
figcontrolled.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("bmi"))
figcontrolled.htn <- mutate(figcontrolled.htn, 
                   lowerci = prob_controlled-(1.96*se_htn),
                   upperci = prob_controlled+(1.96*se_htn))


write.csv(figcontrolled.htn, "regressionfigure_controlled_wealth htn SIMPLEbmi.csv")



figscreenedfinal.htn <- left_join(figscreened.htn, figaware.htn, by = c("bmi"))
figscreenedfinal.htn <- left_join(figscreenedfinal.htn, figtreated.htn, by = c("bmi"))
figscreenedfinal.htn <- left_join(figscreenedfinal.htn, figcontrolled.htn, by = c("bmi"))

figscreenedfinal.htn <- mutate(figscreenedfinal.htn, 
                              prob_screened = prob_screened*100,
                              prob_aware = prob_aware*100,
                              prob_treated = prob_treated*100,
                   prob_controlled = prob_controlled*100)
                   





#####Screened 
stateawarefig <- figscreenedfinal.htn %>% 
    ggplot()+
     geom_histogram(aes(x=bmi, y=(..ncount..)*20), stat="bin", binwidth=1, alpha=0.7) +
 #    geom_point(aes(y=prob_screened, x=bmi), size=0.01, color="cyan") +
  geom_smooth(aes(y=prob_screened, x=bmi),method='loess', se= FALSE, color="blue") +
 #  geom_point(aes(y=prob_aware, x=bmi), size=0.01, color="coral") +
      geom_smooth(aes(y=prob_aware, x=bmi),method='loess', se= FALSE, color="red") +
#  geom_point(aes(y=prob_controlled, x=bmi), size=0.01, color="darkmagenta") +
      geom_smooth(aes(y=prob_controlled, x=bmi),method='loess', se= FALSE, color="purple") +
#   geom_point(aes(y=prob_treated, x=bmi), size=0.01, color="darkgoldenrod1") +
    geom_smooth(aes(y=prob_treated, x=bmi),method='loess', se= FALSE, color="orange") +

# coord_cartesian(xlim = c(15, 45)) +
  theme_classic() + 
  labs(x = "BMI (kg/m^2)",
       y = " Percentage",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(20, 40,60,80,100), limits=c(0, 100)) +
  scale_x_continuous(breaks = c(15,20,25,30,35,40,45), limits=c(15, 45)) +
  coord_fixed(30/100, expand=F)
stateawarefig


  
```





```{r spline regressions screened}

install.packages("rms")
install.packages("broom")
# The rms-setup
library(rms)
ddist <- datadist(dhs_nomiss_rural)
options("datadist" = "ddist")


dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_screened_htn_rural666 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural676 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural636 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural646 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural656 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural766 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural776 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural736 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural746 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural756 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural366 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural376 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural336 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural346 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural356 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural466 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural476 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural436 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural446 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural456 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural566 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural576 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural536 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural546 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural556 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))








dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_screened_htn_rural667 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural677 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural637 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural647 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural657 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural767 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural777 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural737 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural747 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural757 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural367 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural377 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural337 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural347 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural357 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural467 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural477 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural437 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural447 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural457 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural567 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural577 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural537 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural547 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural557 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))









dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_screened_htn_rural663 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural673 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural633 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural643 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural653 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural763 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural773 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural733 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural743 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural753 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural363 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural373 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural333 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural343 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural353 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural463 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural473 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural433 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural443 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural453 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural563 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural573 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural533 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural543 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural553 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))










dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_screened_htn_rural664 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural674 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural634 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural644 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural654 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural764 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural774 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural734 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural744 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural754 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural364 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural374 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural334 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural344 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural354 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural464 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural474 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural434 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural444 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural454 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural564 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural574 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural534 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural544 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural554 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))







dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_screened_htn_rural665 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural675 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural635 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural645 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural655 <- glm(formula = htn_screened_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural765 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural775 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural735 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural745 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural755 <- glm(formula = htn_screened_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_screened_htn_rural365 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural375 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural335 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural345 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural355 <- glm(formula = htn_screened_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural465 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural475 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural435 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural445 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural455 <- glm(formula = htn_screened_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_screened_htn_rural565 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural575 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural535 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural545 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_screened_htn_rural555 <- glm(formula = htn_screened_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




summ.table <- do.call(rbind, lapply(list(multiv_feclust_screened_htn_rural333, multiv_feclust_screened_htn_rural334,multiv_feclust_screened_htn_rural335,multiv_feclust_screened_htn_rural343,multiv_feclust_screened_htn_rural344,multiv_feclust_screened_htn_rural345,multiv_feclust_screened_htn_rural353,multiv_feclust_screened_htn_rural354,multiv_feclust_screened_htn_rural355,multiv_feclust_screened_htn_rural433,multiv_feclust_screened_htn_rural434,multiv_feclust_screened_htn_rural435,multiv_feclust_screened_htn_rural443,multiv_feclust_screened_htn_rural444,multiv_feclust_screened_htn_rural445,multiv_feclust_screened_htn_rural453,multiv_feclust_screened_htn_rural454,multiv_feclust_screened_htn_rural455,multiv_feclust_screened_htn_rural533,multiv_feclust_screened_htn_rural534,multiv_feclust_screened_htn_rural535,multiv_feclust_screened_htn_rural543,multiv_feclust_screened_htn_rural544,multiv_feclust_screened_htn_rural545,multiv_feclust_screened_htn_rural553,multiv_feclust_screened_htn_rural554,multiv_feclust_screened_htn_rural555), broom::glance))

#regress<-c(multiv_feclust_screened_htn_rural333, multiv_feclust_screened_htn_rural334,multiv_feclust_screened_htn_rural335,multiv_feclust_screened_htn_rural343,multiv_feclust_screened_htn_rural344,multiv_feclust_screened_htn_rural345,multiv_feclust_screened_htn_rural353,multiv_feclust_screened_htn_rural354,multiv_feclust_screened_htn_rural355,multiv_feclust_screened_htn_rural433,multiv_feclust_screened_htn_rural434,multiv_feclust_screened_htn_rural435,multiv_feclust_screened_htn_rural443,multiv_feclust_screened_htn_rural444,multiv_feclust_screened_htn_rural445,multiv_feclust_screened_htn_rural453,multiv_feclust_screened_htn_rural454,multiv_feclust_screened_htn_rural455,multiv_feclust_screened_htn_rural533,multiv_feclust_screened_htn_rural534,multiv_feclust_screened_htn_rural535,multiv_feclust_screened_htn_rural543,multiv_feclust_screened_htn_rural544,multiv_feclust_screened_htn_rural545,multiv_feclust_screened_htn_rural553,multiv_feclust_screened_htn_rural554,multiv_feclust_screened_htn_rural555)

#regress.data<-as.data.frame(regress)

#summ.table<- left_join(summ.table,regress)




```

```{r spline regressions aware}

install.packages("rms")
install.packages("broom")
# The rms-setup
library(rms)
ddist <- datadist(dhs_nomiss_rural)
options("datadist" = "ddist")


dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)

multiv_feclust_aware_htn_rural666 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural676 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural636 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural646 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural656 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural766 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural776 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural736 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural746 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural756 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural366 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural376 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural336 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural346 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural356 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural466 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural476 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural436 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural446 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural456 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural566 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural576 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural536 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural546 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural556 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))








dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_aware_htn_rural667 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural677 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural637 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural647 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural657 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural767 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural777 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural737 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural747 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural757 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural367 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural377 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural337 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural347 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural357 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural467 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural477 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural437 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural447 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural457 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural567 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural577 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural537 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural547 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural557 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))









dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_aware_htn_rural663 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural673 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural633 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural643 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural653 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural763 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural773 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural733 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural743 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural753 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural363 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural373 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural333 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural343 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural353 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural463 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural473 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural433 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural443 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural453 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural563 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural573 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural533 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural543 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural553 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))










dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_aware_htn_rural664 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural674 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural634 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural644 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural654 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural764 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural774 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural734 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural744 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural754 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural364 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural374 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural334 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural344 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural354 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural464 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural474 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural434 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural444 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural454 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural564 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural574 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural534 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural544 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural554 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))







dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_aware_htn_rural665 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural675 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural635 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural645 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural655 <- glm(formula = htn_aware_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural765 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural775 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural735 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural745 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural755 <- glm(formula = htn_aware_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_aware_htn_rural365 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural375 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural335 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural345 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural355 <- glm(formula = htn_aware_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural465 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural475 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural435 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural445 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural455 <- glm(formula = htn_aware_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_aware_htn_rural565 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural575 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural535 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural545 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_aware_htn_rural555 <- glm(formula = htn_aware_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




summ.table <- do.call(rbind, lapply(list(multiv_feclust_aware_htn_rural333, multiv_feclust_aware_htn_rural334,multiv_feclust_aware_htn_rural335,multiv_feclust_aware_htn_rural343,multiv_feclust_aware_htn_rural344,multiv_feclust_aware_htn_rural345,multiv_feclust_aware_htn_rural353,multiv_feclust_aware_htn_rural354,multiv_feclust_aware_htn_rural355,multiv_feclust_aware_htn_rural433,multiv_feclust_aware_htn_rural434,multiv_feclust_aware_htn_rural435,multiv_feclust_aware_htn_rural443,multiv_feclust_aware_htn_rural444,multiv_feclust_aware_htn_rural445,multiv_feclust_aware_htn_rural453,multiv_feclust_aware_htn_rural454,multiv_feclust_aware_htn_rural455,multiv_feclust_aware_htn_rural533,multiv_feclust_aware_htn_rural534,multiv_feclust_aware_htn_rural535,multiv_feclust_aware_htn_rural543,multiv_feclust_aware_htn_rural544,multiv_feclust_aware_htn_rural545,multiv_feclust_aware_htn_rural553,multiv_feclust_aware_htn_rural554,multiv_feclust_aware_htn_rural555), broom::glance))

#regress<-c(multiv_feclust_aware_htn_rural333, multiv_feclust_aware_htn_rural334,multiv_feclust_aware_htn_rural335,multiv_feclust_aware_htn_rural343,multiv_feclust_aware_htn_rural344,multiv_feclust_aware_htn_rural345,multiv_feclust_aware_htn_rural353,multiv_feclust_aware_htn_rural354,multiv_feclust_aware_htn_rural355,multiv_feclust_aware_htn_rural433,multiv_feclust_aware_htn_rural434,multiv_feclust_aware_htn_rural435,multiv_feclust_aware_htn_rural443,multiv_feclust_aware_htn_rural444,multiv_feclust_aware_htn_rural445,multiv_feclust_aware_htn_rural453,multiv_feclust_aware_htn_rural454,multiv_feclust_aware_htn_rural455,multiv_feclust_aware_htn_rural533,multiv_feclust_aware_htn_rural534,multiv_feclust_aware_htn_rural535,multiv_feclust_aware_htn_rural543,multiv_feclust_aware_htn_rural544,multiv_feclust_aware_htn_rural545,multiv_feclust_aware_htn_rural553,multiv_feclust_aware_htn_rural554,multiv_feclust_aware_htn_rural555)

#regress.data<-as.data.frame(regress)

#summ.table<- left_join(summ.table,regress)




```

```{r spline regressions treated}

install.packages("rms")
install.packages("broom")
# The rms-setup
library(rms)
ddist <- datadist(dhs_nomiss_rural)
options("datadist" = "ddist")


dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_treated_htn_rural666 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural676 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural636 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural646 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural656 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural766 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural776 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural736 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural746 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural756 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural366 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural376 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural336 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural346 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural356 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural466 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural476 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural436 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural446 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural456 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural566 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural576 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural536 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural546 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural556 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))








dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_treated_htn_rural667 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural677 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural637 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural647 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural657 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural767 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural777 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural737 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural747 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural757 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural367 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural377 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural337 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural347 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural357 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural467 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural477 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural437 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural447 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural457 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural567 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural577 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural537 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural547 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural557 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))









dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_treated_htn_rural663 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural673 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural633 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural643 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural653 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural763 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural773 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural733 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural743 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural753 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural363 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural373 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural333 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural343 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural353 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural463 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural473 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural433 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural443 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural453 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural563 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural573 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural533 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural543 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural553 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))










dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_treated_htn_rural664 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural674 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural634 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural644 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural654 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural764 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural774 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural734 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural744 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural754 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural364 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural374 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural334 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural344 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural354 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural464 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural474 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural434 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural444 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural454 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural564 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural574 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural534 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural544 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural554 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))







dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_treated_htn_rural665 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural675 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural635 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural645 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural655 <- glm(formula = htn_treated_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural765 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural775 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural735 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural745 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural755 <- glm(formula = htn_treated_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_treated_htn_rural365 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural375 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural335 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural345 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural355 <- glm(formula = htn_treated_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural465 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural475 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural435 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural445 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural455 <- glm(formula = htn_treated_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_treated_htn_rural565 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural575 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural535 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural545 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_treated_htn_rural555 <- glm(formula = htn_treated_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




summ.table <- do.call(rbind, lapply(list(multiv_feclust_treated_htn_rural333, multiv_feclust_treated_htn_rural334,multiv_feclust_treated_htn_rural335,multiv_feclust_treated_htn_rural343,multiv_feclust_treated_htn_rural344,multiv_feclust_treated_htn_rural345,multiv_feclust_treated_htn_rural353,multiv_feclust_treated_htn_rural354,multiv_feclust_treated_htn_rural355,multiv_feclust_treated_htn_rural433,multiv_feclust_treated_htn_rural434,multiv_feclust_treated_htn_rural435,multiv_feclust_treated_htn_rural443,multiv_feclust_treated_htn_rural444,multiv_feclust_treated_htn_rural445,multiv_feclust_treated_htn_rural453,multiv_feclust_treated_htn_rural454,multiv_feclust_treated_htn_rural455,multiv_feclust_treated_htn_rural533,multiv_feclust_treated_htn_rural534,multiv_feclust_treated_htn_rural535,multiv_feclust_treated_htn_rural543,multiv_feclust_treated_htn_rural544,multiv_feclust_treated_htn_rural545,multiv_feclust_treated_htn_rural553,multiv_feclust_treated_htn_rural554,multiv_feclust_treated_htn_rural555), broom::glance))

#regress<-c(multiv_feclust_treated_htn_rural333, multiv_feclust_treated_htn_rural334,multiv_feclust_treated_htn_rural335,multiv_feclust_treated_htn_rural343,multiv_feclust_treated_htn_rural344,multiv_feclust_treated_htn_rural345,multiv_feclust_treated_htn_rural353,multiv_feclust_treated_htn_rural354,multiv_feclust_treated_htn_rural355,multiv_feclust_treated_htn_rural433,multiv_feclust_treated_htn_rural434,multiv_feclust_treated_htn_rural435,multiv_feclust_treated_htn_rural443,multiv_feclust_treated_htn_rural444,multiv_feclust_treated_htn_rural445,multiv_feclust_treated_htn_rural453,multiv_feclust_treated_htn_rural454,multiv_feclust_treated_htn_rural455,multiv_feclust_treated_htn_rural533,multiv_feclust_treated_htn_rural534,multiv_feclust_treated_htn_rural535,multiv_feclust_treated_htn_rural543,multiv_feclust_treated_htn_rural544,multiv_feclust_treated_htn_rural545,multiv_feclust_treated_htn_rural553,multiv_feclust_treated_htn_rural554,multiv_feclust_treated_htn_rural555)

#regress.data<-as.data.frame(regress)

#summ.table<- left_join(summ.table,regress)




```

```{r spline regressions controlled}

install.packages("rms")
install.packages("broom")
# The rms-setup
library(rms)
ddist <- datadist(dhs_nomiss_rural)
options("datadist" = "ddist")


dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_controlled_htn_rural666 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural676 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural636 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural646 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural656 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural766 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural776 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural736 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural746 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural756 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural366 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural376 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural336 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural346 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural356 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural466 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural476 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural436 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural446 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural456 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural566 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural576 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural536 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural546 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural556 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,6) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))








dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_controlled_htn_rural667 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural677 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural637 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural647 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural657 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural767 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural777 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural737 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural747 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural757 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural367 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural377 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural337 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural347 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural357 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural467 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural477 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural437 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural447 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural457 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural567 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural577 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural537 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural547 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural557 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,7) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))









dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_controlled_htn_rural663 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural673 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural633 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural643 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural653 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural763 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural773 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural733 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural743 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural753 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural363 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural373 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural333 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural343 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural353 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural463 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural473 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural433 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural443 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural453 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural563 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural573 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural533 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural543 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural553 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))










dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_controlled_htn_rural664 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural674 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural634 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural644 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural654 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural764 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural774 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural734 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural744 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural754 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural364 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural374 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural334 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural344 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural354 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural464 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural474 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural434 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural444 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural454 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural564 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural574 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural534 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural544 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural554 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,4) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))







dhs_nomiss_spline_rural$asset_index <-as.numeric(dhs_nomiss_spline_rural$asset_index)
multiv_feclust_controlled_htn_rural665 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural675 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural635 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural645 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural655 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural765 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural775 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural735 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural745 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural755 <- glm(formula = htn_controlled_dbl ~ rcs(age,7) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))




multiv_feclust_controlled_htn_rural365 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural375 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural335 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural345 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural355 <- glm(formula = htn_controlled_dbl ~ rcs(age,3) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural465 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural475 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural435 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural445 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural455 <- glm(formula = htn_controlled_dbl ~ rcs(age,4) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))



multiv_feclust_controlled_htn_rural565 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,6) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural575 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,7) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural535 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,3) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural545 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,4) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural555 <- glm(formula = htn_controlled_dbl ~ rcs(age,5) + rcs(asset_index,5) + educatnames + married +sex + rcs(bmi,5) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))


install.packages("broom")
library(broom)

summ.table <- do.call(rbind, lapply(list(multiv_feclust_controlled_htn_rural333, multiv_feclust_controlled_htn_rural334,multiv_feclust_controlled_htn_rural335,multiv_feclust_controlled_htn_rural336,multiv_feclust_controlled_htn_rural337,multiv_feclust_controlled_htn_rural343,multiv_feclust_controlled_htn_rural344,multiv_feclust_controlled_htn_rural345,multiv_feclust_controlled_htn_rural346,multiv_feclust_controlled_htn_rural347,multiv_feclust_controlled_htn_rural353,multiv_feclust_controlled_htn_rural354,multiv_feclust_controlled_htn_rural355,multiv_feclust_controlled_htn_rural356,multiv_feclust_controlled_htn_rural445,multiv_feclust_controlled_htn_rural453,multiv_feclust_controlled_htn_rural454,multiv_feclust_controlled_htn_rural357,multiv_feclust_controlled_htn_rural363,multiv_feclust_controlled_htn_rural364,multiv_feclust_controlled_htn_rural365,multiv_feclust_controlled_htn_rural366,multiv_feclust_controlled_htn_rural367,multiv_feclust_controlled_htn_rural373,multiv_feclust_controlled_htn_rural374,multiv_feclust_controlled_htn_rural375,multiv_feclust_controlled_htn_rural376,multiv_feclust_controlled_htn_rural376,multiv_feclust_controlled_htn_rural376,multiv_feclust_controlled_htn_rural376,multiv_feclust_controlled_htn_rural377,multiv_feclust_controlled_htn_rural433,multiv_feclust_controlled_htn_rural434,multiv_feclust_controlled_htn_rural435,multiv_feclust_controlled_htn_rural436,multiv_feclust_controlled_htn_rural437,multiv_feclust_controlled_htn_rural443,multiv_feclust_controlled_htn_rural444,multiv_feclust_controlled_htn_rural445,multiv_feclust_controlled_htn_rural446,multiv_feclust_controlled_htn_rural447,multiv_feclust_controlled_htn_rural453,multiv_feclust_controlled_htn_rural454,multiv_feclust_controlled_htn_rural455,multiv_feclust_controlled_htn_rural456,multiv_feclust_controlled_htn_rural457,multiv_feclust_controlled_htn_rural463,multiv_feclust_controlled_htn_rural464,multiv_feclust_controlled_htn_rural465,multiv_feclust_controlled_htn_rural466,multiv_feclust_controlled_htn_rural467,multiv_feclust_controlled_htn_rural453,multiv_feclust_controlled_htn_rural454,multiv_feclust_controlled_htn_rural455,multiv_feclust_controlled_htn_rural456,multiv_feclust_controlled_htn_rural457,multiv_feclust_controlled_htn_rural463,multiv_feclust_controlled_htn_rural464,multiv_feclust_controlled_htn_rural465,multiv_feclust_controlled_htn_rural466,multiv_feclust_controlled_htn_rural467,multiv_feclust_controlled_htn_rural473,multiv_feclust_controlled_htn_rural474,multiv_feclust_controlled_htn_rural475,multiv_feclust_controlled_htn_rural476,multiv_feclust_controlled_htn_rural477,multiv_feclust_controlled_htn_rural533,multiv_feclust_controlled_htn_rural534,multiv_feclust_controlled_htn_rural535,multiv_feclust_controlled_htn_rural536,multiv_feclust_controlled_htn_rural537,multiv_feclust_controlled_htn_rural543,multiv_feclust_controlled_htn_rural544,multiv_feclust_controlled_htn_rural545,multiv_feclust_controlled_htn_rural546,multiv_feclust_controlled_htn_rural547,multiv_feclust_controlled_htn_rural553,multiv_feclust_controlled_htn_rural554,multiv_feclust_controlled_htn_rural555,multiv_feclust_controlled_htn_rural556,multiv_feclust_controlled_htn_rural557,multiv_feclust_controlled_htn_rural563,multiv_feclust_controlled_htn_rural564,multiv_feclust_controlled_htn_rural565,multiv_feclust_controlled_htn_rural566),broom::glance))


summ.table1 <- do.call(rbind, lapply(list(multiv_feclust_controlled_htn_rural567,multiv_feclust_controlled_htn_rural577,multiv_feclust_controlled_htn_rural633,multiv_feclust_controlled_htn_rural634,multiv_feclust_controlled_htn_rural635,multiv_feclust_controlled_htn_rural636,multiv_feclust_controlled_htn_rural637,multiv_feclust_controlled_htn_rural643,multiv_feclust_controlled_htn_rural644,multiv_feclust_controlled_htn_rural645,multiv_feclust_controlled_htn_rural646,multiv_feclust_controlled_htn_rural647,multiv_feclust_controlled_htn_rural653,multiv_feclust_controlled_htn_rural654,multiv_feclust_controlled_htn_rural655,multiv_feclust_controlled_htn_rural656,multiv_feclust_controlled_htn_rural657,multiv_feclust_controlled_htn_rural663,multiv_feclust_controlled_htn_rural664,multiv_feclust_controlled_htn_rural665,multiv_feclust_controlled_htn_rural666,multiv_feclust_controlled_htn_rural667,multiv_feclust_controlled_htn_rural673,multiv_feclust_controlled_htn_rural674,multiv_feclust_controlled_htn_rural675,multiv_feclust_controlled_htn_rural677,multiv_feclust_controlled_htn_rural677,multiv_feclust_controlled_htn_rural733,multiv_feclust_controlled_htn_rural734,multiv_feclust_controlled_htn_rural735,multiv_feclust_controlled_htn_rural736,multiv_feclust_controlled_htn_rural737,multiv_feclust_controlled_htn_rural743,multiv_feclust_controlled_htn_rural744,multiv_feclust_controlled_htn_rural745,multiv_feclust_controlled_htn_rural746,multiv_feclust_controlled_htn_rural747,multiv_feclust_controlled_htn_rural753,multiv_feclust_controlled_htn_rural754,multiv_feclust_controlled_htn_rural755,multiv_feclust_controlled_htn_rural756,multiv_feclust_controlled_htn_rural757,multiv_feclust_controlled_htn_rural763,multiv_feclust_controlled_htn_rural764,multiv_feclust_controlled_htn_rural765,multiv_feclust_controlled_htn_rural766,multiv_feclust_controlled_htn_rural767,multiv_feclust_controlled_htn_rural773,multiv_feclust_controlled_htn_rural774,multiv_feclust_controlled_htn_rural775,multiv_feclust_controlled_htn_rural776,multiv_feclust_controlled_htn_rural777),broom::glance))


reg1<-c("multiv_feclust_controlled_htn_rural333", "multiv_feclust_controlled_htn_rural334","multiv_feclust_controlled_htn_rural335","multiv_feclust_controlled_htn_rural336","multiv_feclust_controlled_htn_rural337","multiv_feclust_controlled_htn_rural343","multiv_feclust_controlled_htn_rural344","multiv_feclust_controlled_htn_rural345","multiv_feclust_controlled_htn_rural346","multiv_feclust_controlled_htn_rural347","multiv_feclust_controlled_htn_rural353","multiv_feclust_controlled_htn_rural354","multiv_feclust_controlled_htn_rural355","multiv_feclust_controlled_htn_rural356","multiv_feclust_controlled_htn_rural445","multiv_feclust_controlled_htn_rural453","multiv_feclust_controlled_htn_rural454","multiv_feclust_controlled_htn_rural357","multiv_feclust_controlled_htn_rural363","multiv_feclust_controlled_htn_rural364","multiv_feclust_controlled_htn_rural365","multiv_feclust_controlled_htn_rural366","multiv_feclust_controlled_htn_rural367","multiv_feclust_controlled_htn_rural373","multiv_feclust_controlled_htn_rural374","multiv_feclust_controlled_htn_rural375","multiv_feclust_controlled_htn_rural376","multiv_feclust_controlled_htn_rural376","multiv_feclust_controlled_htn_rural376","multiv_feclust_controlled_htn_rural376","multiv_feclust_controlled_htn_rural377","multiv_feclust_controlled_htn_rural433","multiv_feclust_controlled_htn_rural434","multiv_feclust_controlled_htn_rural435","multiv_feclust_controlled_htn_rural436","multiv_feclust_controlled_htn_rural437","multiv_feclust_controlled_htn_rural443","multiv_feclust_controlled_htn_rural444","multiv_feclust_controlled_htn_rural445","multiv_feclust_controlled_htn_rural446","multiv_feclust_controlled_htn_rural447","multiv_feclust_controlled_htn_rural453","multiv_feclust_controlled_htn_rural454","multiv_feclust_controlled_htn_rural455","multiv_feclust_controlled_htn_rural456","multiv_feclust_controlled_htn_rural457","multiv_feclust_controlled_htn_rural463","multiv_feclust_controlled_htn_rural464","multiv_feclust_controlled_htn_rural465","multiv_feclust_controlled_htn_rural466","multiv_feclust_controlled_htn_rural467","multiv_feclust_controlled_htn_rural453","multiv_feclust_controlled_htn_rural454","multiv_feclust_controlled_htn_rural455","multiv_feclust_controlled_htn_rural456","multiv_feclust_controlled_htn_rural457","multiv_feclust_controlled_htn_rural463","multiv_feclust_controlled_htn_rural464","multiv_feclust_controlled_htn_rural465","multiv_feclust_controlled_htn_rural466","multiv_feclust_controlled_htn_rural467","multiv_feclust_controlled_htn_rural473","multiv_feclust_controlled_htn_rural474","multiv_feclust_controlled_htn_rural475","multiv_feclust_controlled_htn_rural476","multiv_feclust_controlled_htn_rural477","multiv_feclust_controlled_htn_rural533","multiv_feclust_controlled_htn_rural534","multiv_feclust_controlled_htn_rural535","multiv_feclust_controlled_htn_rural536","multiv_feclust_controlled_htn_rural537","multiv_feclust_controlled_htn_rural543","multiv_feclust_controlled_htn_rural544","multiv_feclust_controlled_htn_rural545","multiv_feclust_controlled_htn_rural546","multiv_feclust_controlled_htn_rural547","multiv_feclust_controlled_htn_rural553","multiv_feclust_controlled_htn_rural554","multiv_feclust_controlled_htn_rural555","multiv_feclust_controlled_htn_rural556","multiv_feclust_controlled_htn_rural557","multiv_feclust_controlled_htn_rural563","multiv_feclust_controlled_htn_rural564","multiv_feclust_controlled_htn_rural565","multiv_feclust_controlled_htn_rural566")

reg2<-c("multiv_feclust_controlled_htn_rural567","multiv_feclust_controlled_htn_rural577","multiv_feclust_controlled_htn_rural633","multiv_feclust_controlled_htn_rural634","multiv_feclust_controlled_htn_rural635","multiv_feclust_controlled_htn_rural636","multiv_feclust_controlled_htn_rural637","multiv_feclust_controlled_htn_rural643","multiv_feclust_controlled_htn_rural644","multiv_feclust_controlled_htn_rural645","multiv_feclust_controlled_htn_rural646","multiv_feclust_controlled_htn_rural647","multiv_feclust_controlled_htn_rural653","multiv_feclust_controlled_htn_rural654","multiv_feclust_controlled_htn_rural655","multiv_feclust_controlled_htn_rural656","multiv_feclust_controlled_htn_rural657","multiv_feclust_controlled_htn_rural663","multiv_feclust_controlled_htn_rural664","multiv_feclust_controlled_htn_rural665","multiv_feclust_controlled_htn_rural666","multiv_feclust_controlled_htn_rural667","multiv_feclust_controlled_htn_rural673","multiv_feclust_controlled_htn_rural674","multiv_feclust_controlled_htn_rural675","multiv_feclust_controlled_htn_rural677","multiv_feclust_controlled_htn_rural677","multiv_feclust_controlled_htn_rural733","multiv_feclust_controlled_htn_rural734","multiv_feclust_controlled_htn_rural735","multiv_feclust_controlled_htn_rural736","multiv_feclust_controlled_htn_rural737","multiv_feclust_controlled_htn_rural743","multiv_feclust_controlled_htn_rural744","multiv_feclust_controlled_htn_rural745","multiv_feclust_controlled_htn_rural746","multiv_feclust_controlled_htn_rural747","multiv_feclust_controlled_htn_rural753","multiv_feclust_controlled_htn_rural754","multiv_feclust_controlled_htn_rural755","multiv_feclust_controlled_htn_rural756","multiv_feclust_controlled_htn_rural757","multiv_feclust_controlled_htn_rural763","multiv_feclust_controlled_htn_rural764","multiv_feclust_controlled_htn_rural765","multiv_feclust_controlled_htn_rural766","multiv_feclust_controlled_htn_rural767","multiv_feclust_controlled_htn_rural773","multiv_feclust_controlled_htn_rural774","multiv_feclust_controlled_htn_rural775","multiv_feclust_controlled_htn_rural776","multiv_feclust_controlled_htn_rural777")


summ.table <- mutate(summ.table,
                     regression = reg1)

write.csv(summ.table,"AICs_part1.csv")

summ.table1 <- mutate(summ.table1,
                     regression = reg2)

write.csv(summ.table1,"AICs_part2.csv")



summ.table <- do.call(rbind, lapply(list(m1, m2, m3), broom::glance))



#regress.data<-as.data.frame(regress)

#summ.table<- left_join(summ.table,regress)


#Check

multiv_feclust_controlled_htn_rural683 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,8) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural693 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,9) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural6103 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,10) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural6113 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,11) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural6123 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,12) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural6133 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,13) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

multiv_feclust_controlled_htn_rural6143 <- glm(formula = htn_controlled_dbl ~ rcs(age,6) + rcs(asset_index,14) + educatnames + married +sex + rcs(bmi,3) + tobacco_smoked + tobacco_smokeless + d_id  ,  weights= p_wt_new,  data=dhs_nomiss_spline_rural, family=binomial(link="logit"))

summ.table1 <- do.call(rbind, lapply(list(multiv_feclust_controlled_htn_rural683,multiv_feclust_controlled_htn_rural693,multiv_feclust_controlled_htn_rural6103,multiv_feclust_controlled_htn_rural6113,multiv_feclust_controlled_htn_rural6123,multiv_feclust_controlled_htn_rural6133,multiv_feclust_controlled_htn_rural6143),broom::glance))


reg1<-c("multiv_feclust_controlled_htn_rural683","multiv_feclust_controlled_htn_rural693","multiv_feclust_controlled_htn_rural6103","multiv_feclust_controlled_htn_rural6113","multiv_feclust_controlled_htn_rural6123","multiv_feclust_controlled_htn_rural6133","multiv_feclust_controlled_htn_rural6143")

summ.table1 <- mutate(summ.table1,
                     regression = reg1)



```


```{r univariable regressions}

#######SCREENED RURAL

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked OR regression results screened ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked p-Value screened ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened rural.csv")




#######SCREENED urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results screened urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value screened urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened urban.csv")






#######aware rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware rural.csv")







#######aware urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware urban.csv")




#######treated rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated rural.csv")




#######treated urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated urban.csv")







#######controlled rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled rural.csv")










#######controlled urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled urban.csv")













#univariable regressions#


#Rural screened

age <- glm.cluster(formula = htn_screened_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results screened ruralunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value screened ruralunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened rural univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value screened ruralunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_screened_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results screened ruralunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value screened ruralunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_screened_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results screened ruralunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value screened ruralunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_screened_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results screened ruralunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value screened ruralunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_screened_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results screened ruralunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value screened ruralunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco smoked OR regression results screened ruralunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco smoked p-Value screened ruralunivariable regpoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened ruralunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened ruralunivariable regpoisson.csv")


#Urban screened

age <- glm.cluster(formula = htn_screened_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results screened urbanunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value screened urbanunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened urban univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value screened urbanunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_screened_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results screened urbanunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value screened urbanunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_screened_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results screened urbanunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value screened urbanunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_screened_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results screened urbanunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value screened urbanunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_screened_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results screened urbanunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value screened urbanunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results screened urbanunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value screened urbanunivariable regpoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened urbanunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened urbanunivariable regpoisson.csv")


#Rural aware

age <- glm.cluster(formula = htn_aware_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results aware ruralunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value aware ruralunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware rural univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value aware ruralunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_aware_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results aware ruralunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value aware ruralunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_aware_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results aware ruralunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value aware ruralunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_aware_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results aware ruralunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value aware ruralunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_aware_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results aware ruralunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value aware ruralunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware ruralunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware ruralunivariable regpoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware ruralunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware ruralunivariable regpoisson.csv")


###aware urban



age <- glm.cluster(formula = htn_aware_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results aware urbanunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value aware urbanunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware urban univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value aware urbanunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_aware_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results aware urbanunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value aware urbanunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_aware_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results aware urbanunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value aware urbanunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_aware_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results aware urbanunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value aware urbanunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_aware_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results aware urbanunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value aware urbanunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware urbanunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware urbanunivariable regpoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware urbanunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware urbanunivariable regpoisson.csv")



#rural treated


age <- glm.cluster(formula = htn_treated_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results treated ruralunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value treated ruralunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated rural univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value treated ruralunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_treated_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results treated ruralunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value treated ruralunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_treated_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results treated ruralunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value treated ruralunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_treated_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results treated ruralunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value treated ruralunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_treated_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results treated ruralunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value treated ruralunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated ruralunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated ruralunivariable regpoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated ruralunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated ruralunivariable regpoisson.csv")

#urban treated

age <- glm.cluster(formula = htn_treated_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results treated urbanunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value treated urbanunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated urban univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value treated urbanunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_treated_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results treated urbanunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value treated urbanunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_treated_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results treated urbanunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value treated urbanunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_treated_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results treated urbanunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value treated urbanunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_treated_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results treated urbanunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value treated urbanunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated urbanunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated urbanunivariable regpoisson.csv")


tobacco_smokeless <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated urbanunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated urbanunivariable regpoisson.csv")



#rural controlled

age <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results controlled ruralunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value controlled ruralunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled rural univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value controlled ruralunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_controlled_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results controlled ruralunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value controlled ruralunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_controlled_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results controlled ruralunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value controlled ruralunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_controlled_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results controlled ruralunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value controlled ruralunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_controlled_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled ruralunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value controlled ruralunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled ruralunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled ruralunivariable regpoisson.csv")


tobacco_smokeless <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled ruralunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled ruralunivariable regpoisson.csv")

#urban controlled

age <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results controlled urbanunivariable regpoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value controlled urbanunivariable regpoisson.csv")

wealth <- glm.cluster(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled urban univariable regpoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value controlled urbanunivariable regpoisson.csv")

educat <- glm.cluster(formula = htn_controlled_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results controlled urbanunivariable regpoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value controlled urbanunivariable regpoisson.csv")

married <- glm.cluster(formula = htn_controlled_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results controlled urbanunivariable regpoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value controlled urbanunivariable regpoisson.csv")

sex <- glm.cluster(formula = htn_controlled_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results controlled urbanunivariable regpoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value controlled urbanunivariable regpoisson.csv")

bmi <- glm.cluster(formula = htn_controlled_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled urbanunivariable regpoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value controlled urbanunivariable regpoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled urbanunivariable regpoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled urbanunivariable regpoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled urbanunivariable regpoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled urbanunivariable regpoisson.csv")


```


```{r univariable with WEIGHTS}

#univariable regressions WITH WEIGHTS#


#Rural screened

age <- glm(formula = htn_screened_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results screened ruralunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value screened ruralunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened rural univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value screened ruralunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_screened_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results screened ruralunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value screened ruralunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_screened_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results screened ruralunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value screened ruralunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_screened_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results screened ruralunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value screened ruralunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_screened_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results screened ruralunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value screened ruralunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco smoked OR regression results screened ruralunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco smoked p-Value screened ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless <- glm(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened ruralunivariable reg with weightspoisson.csv")


#Urban screened

age <- glm(formula = htn_screened_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results screened urbanunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value screened urbanunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened urban univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value screened urbanunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_screened_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results screened urbanunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value screened urbanunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_screened_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results screened urbanunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value screened urbanunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_screened_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results screened urbanunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value screened urbanunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_screened_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results screened urbanunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value screened urbanunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results screened urbanunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value screened urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless <- glm(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened urbanunivariable reg with weightspoisson.csv")


#Rural aware

age <- glm(formula = htn_aware_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results aware ruralunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value aware ruralunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware rural univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value aware ruralunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_aware_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results aware ruralunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value aware ruralunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_aware_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results aware ruralunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value aware ruralunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_aware_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results aware ruralunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value aware ruralunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_aware_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results aware ruralunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value aware ruralunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware ruralunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless <- glm(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware ruralunivariable reg with weightspoisson.csv")


###aware urban



age <- glm(formula = htn_aware_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results aware urbanunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value aware urbanunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware urban univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value aware urbanunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_aware_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results aware urbanunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value aware urbanunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_aware_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results aware urbanunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value aware urbanunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_aware_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results aware urbanunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value aware urbanunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_aware_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results aware urbanunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value aware urbanunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware urbanunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless <- glm(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware urbanunivariable reg with weightspoisson.csv")



#rural treated


age <- glm(formula = htn_treated_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results treated ruralunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value treated ruralunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated rural univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value treated ruralunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_treated_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results treated ruralunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value treated ruralunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_treated_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results treated ruralunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value treated ruralunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_treated_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results treated ruralunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value treated ruralunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_treated_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results treated ruralunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value treated ruralunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated ruralunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless <- glm(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated ruralunivariable reg with weightspoisson.csv")

#urban treated

age <- glm(formula = htn_treated_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results treated urbanunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value treated urbanunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated urban univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value treated urbanunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_treated_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results treated urbanunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value treated urbanunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_treated_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results treated urbanunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value treated urbanunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_treated_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results treated urbanunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value treated urbanunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_treated_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results treated urbanunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value treated urbanunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated urbanunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated urbanunivariable reg with weightspoisson.csv")


tobacco_smokeless <- glm(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated urbanunivariable reg with weightspoisson.csv")



#rural controlled

age <- glm(formula = htn_controlled_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results controlled ruralunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value controlled ruralunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled rural univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value controlled ruralunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_controlled_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results controlled ruralunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value controlled ruralunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_controlled_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results controlled ruralunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value controlled ruralunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_controlled_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results controlled ruralunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value controlled ruralunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_controlled_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled ruralunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value controlled ruralunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled ruralunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled ruralunivariable reg with weightspoisson.csv")


tobacco_smokeless <- glm(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_rural, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled ruralunivariable reg with weightspoisson.csv")

#urban controlled

age <- glm(formula = htn_controlled_dbl ~ age_grp2  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results controlled urbanunivariable reg with weightspoisson.csv")

age_reg <-summary(age)$coefficients
write.csv(age_reg, "age p-Value controlled urbanunivariable reg with weightspoisson.csv")

wealth <- glm(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled urban univariable reg with weightspoisson.csv")

wealth_reg <-summary(wealth)$coefficients
write.csv(wealth_reg, "wealth p-Value controlled urbanunivariable reg with weightspoisson.csv")

educat <- glm(formula = htn_controlled_dbl ~ educatnames  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results controlled urbanunivariable reg with weightspoisson.csv")

educat_reg <-summary(educat)$coefficients
write.csv(educat_reg, "educat p-Value controlled urbanunivariable reg with weightspoisson.csv")

married <- glm(formula = htn_controlled_dbl ~ married + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results controlled urbanunivariable reg with weightspoisson.csv")

married_reg <-summary(married)$coefficients
write.csv(married_reg, "married p-Value controlled urbanunivariable reg with weightspoisson.csv")

sex <- glm(formula = htn_controlled_dbl ~ sex  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results controlled urbanunivariable reg with weightspoisson.csv")

sex_reg <-summary(sex)$coefficients
write.csv(sex_reg, "sex p-Value controlled urbanunivariable reg with weightspoisson.csv")

bmi <- glm(formula = htn_controlled_dbl ~ bmi_group  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled urbanunivariable reg with weightspoisson.csv")

bmi_reg <-summary(bmi)$coefficients
write.csv(bmi_reg, "bmi p-Value controlled urbanunivariable reg with weightspoisson.csv")

tobacco_smoked <- glm(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled urbanunivariable reg with weightspoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)$coefficients
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless <- glm(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , weights= p_wt_new, data=dhs_nomiss_htn_only_urban, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)$coefficients
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled urbanunivariable reg with weightspoisson.csv")

```

```{r univariable men}
#univariable reg men#


#Rural screened

age <- glm.cluster(formula = htn_screened_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results screened ruralunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value screened ruralunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened rural univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value screened ruralunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_screened_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results screened ruralunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value screened ruralunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_screened_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results screened ruralunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value screened ruralunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_screened_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results screened ruralunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value screened ruralunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_screened_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results screened ruralunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value screened ruralunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco smoked OR regression results screened ruralunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco smoked p-Value screened ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened ruralunivariable reg men onlypoisson.csv")


#Urban screened

age <- glm.cluster(formula = htn_screened_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results screened urbanunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value screened urbanunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened urban univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value screened urbanunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_screened_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results screened urbanunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value screened urbanunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_screened_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results screened urbanunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value screened urbanunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_screened_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results screened urbanunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value screened urbanunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_screened_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results screened urbanunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value screened urbanunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results screened urbanunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value screened urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened urbanunivariable reg men onlypoisson.csv")


#Rural aware

age <- glm.cluster(formula = htn_aware_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results aware ruralunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value aware ruralunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware rural univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value aware ruralunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_aware_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results aware ruralunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value aware ruralunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_aware_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results aware ruralunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value aware ruralunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_aware_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results aware ruralunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value aware ruralunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_aware_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results aware ruralunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value aware ruralunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware ruralunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware ruralunivariable reg men onlypoisson.csv")


###aware urban



age <- glm.cluster(formula = htn_aware_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results aware urbanunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value aware urbanunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware urban univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value aware urbanunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_aware_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results aware urbanunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value aware urbanunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_aware_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results aware urbanunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value aware urbanunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_aware_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results aware urbanunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value aware urbanunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_aware_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results aware urbanunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value aware urbanunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware urbanunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware urbanunivariable reg men onlypoisson.csv")



#rural treated


age <- glm.cluster(formula = htn_treated_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results treated ruralunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value treated ruralunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated rural univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value treated ruralunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_treated_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results treated ruralunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value treated ruralunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_treated_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results treated ruralunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value treated ruralunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_treated_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results treated ruralunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value treated ruralunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_treated_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results treated ruralunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value treated ruralunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated ruralunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated ruralunivariable reg men onlypoisson.csv")

#urban treated

age <- glm.cluster(formula = htn_treated_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results treated urbanunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value treated urbanunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated urban univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value treated urbanunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_treated_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results treated urbanunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value treated urbanunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_treated_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results treated urbanunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value treated urbanunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_treated_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results treated urbanunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value treated urbanunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_treated_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results treated urbanunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value treated urbanunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated urbanunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated urbanunivariable reg men onlypoisson.csv")


tobacco_smokeless <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated urbanunivariable reg men onlypoisson.csv")



#rural controlled

age <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results controlled ruralunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value controlled ruralunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled rural univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value controlled ruralunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_controlled_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results controlled ruralunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value controlled ruralunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_controlled_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results controlled ruralunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value controlled ruralunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_controlled_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results controlled ruralunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value controlled ruralunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_controlled_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled ruralunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value controlled ruralunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled ruralunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled ruralunivariable reg men onlypoisson.csv")


tobacco_smokeless <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled ruralunivariable reg men onlypoisson.csv")

#urban controlled

age <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint(age)))
write.csv(agesheet, "age OR regression results controlled urbanunivariable reg men onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value controlled urbanunivariable reg men onlypoisson.csv")

wealth <- glm.cluster(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled urban univariable reg men onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value controlled urbanunivariable reg men onlypoisson.csv")

educat <- glm.cluster(formula = htn_controlled_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint(educat)))
write.csv(educatsheet, "educat OR regression results controlled urbanunivariable reg men onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value controlled urbanunivariable reg men onlypoisson.csv")

married <- glm.cluster(formula = htn_controlled_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint(married)))
write.csv(marriedsheet, "married OR regression results controlled urbanunivariable reg men onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value controlled urbanunivariable reg men onlypoisson.csv")

sex <- glm.cluster(formula = htn_controlled_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint(sex)))
write.csv(sexsheet, "sex OR regression results controlled urbanunivariable reg men onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value controlled urbanunivariable reg men onlypoisson.csv")

bmi <- glm.cluster(formula = htn_controlled_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled urbanunivariable reg men onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value controlled urbanunivariable reg men onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled urbanunivariable reg men onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_men, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled urbanunivariable reg men onlypoisson.csv")

```


```{r univariable women}
#univariable reg women#




#Rural screened

age <- glm.cluster(formula = htn_screened_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results screened ruralunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value screened ruralunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened rural univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value screened ruralunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_screened_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results screened ruralunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value screened ruralunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_screened_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results screened ruralunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value screened ruralunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_screened_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results screened ruralunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value screened ruralunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_screened_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results screened ruralunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value screened ruralunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco smoked OR regression results screened ruralunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco smoked p-Value screened ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened ruralunivariable reg women onlypoisson.csv")


#Urban screened

age <- glm.cluster(formula = htn_screened_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results screened urbanunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value screened urbanunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_screened_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results screened urban univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value screened urbanunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_screened_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results screened urbanunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value screened urbanunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_screened_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results screened urbanunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value screened urbanunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_screened_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results screened urbanunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value screened urbanunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_screened_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results screened urbanunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value screened urbanunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results screened urbanunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value screened urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_screened_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results screened urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value screened urbanunivariable reg women onlypoisson.csv")


#Rural aware

age <- glm.cluster(formula = htn_aware_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results aware ruralunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value aware ruralunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware rural univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value aware ruralunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_aware_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results aware ruralunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value aware ruralunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_aware_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results aware ruralunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value aware ruralunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_aware_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results aware ruralunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value aware ruralunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_aware_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results aware ruralunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value aware ruralunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware ruralunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware ruralunivariable reg women onlypoisson.csv")


###aware urban



age <- glm.cluster(formula = htn_aware_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results aware urbanunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value aware urbanunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_aware_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results aware urban univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value aware urbanunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_aware_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results aware urbanunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value aware urbanunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_aware_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results aware urbanunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value aware urbanunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_aware_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results aware urbanunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value aware urbanunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_aware_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results aware urbanunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value aware urbanunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results aware urbanunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value aware urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_aware_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results aware urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value aware urbanunivariable reg women onlypoisson.csv")



#rural treated


age <- glm.cluster(formula = htn_treated_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results treated ruralunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value treated ruralunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated rural univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value treated ruralunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_treated_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results treated ruralunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value treated ruralunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_treated_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results treated ruralunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value treated ruralunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_treated_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results treated ruralunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value treated ruralunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_treated_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results treated ruralunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value treated ruralunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated ruralunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated ruralunivariable reg women onlypoisson.csv")

#urban treated

age <- glm.cluster(formula = htn_treated_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results treated urbanunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value treated urbanunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_treated_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results treated urban univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value treated urbanunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_treated_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results treated urbanunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value treated urbanunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_treated_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results treated urbanunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value treated urbanunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_treated_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results treated urbanunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value treated urbanunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_treated_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results treated urbanunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value treated urbanunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results treated urbanunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value treated urbanunivariable reg women onlypoisson.csv")


tobacco_smokeless <- glm.cluster(formula = htn_treated_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results treated urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value treated urbanunivariable reg women onlypoisson.csv")



#rural controlled

age <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results controlled ruralunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value controlled ruralunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled rural univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value controlled ruralunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_controlled_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results controlled ruralunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value controlled ruralunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_controlled_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results controlled ruralunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value controlled ruralunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_controlled_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results controlled ruralunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value controlled ruralunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_controlled_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled ruralunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value controlled ruralunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled ruralunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled ruralunivariable reg women onlypoisson.csv")


tobacco_smokeless <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_rural_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled ruralunivariable reg women onlypoisson.csv")

#urban controlled

age <- glm.cluster(formula = htn_controlled_dbl ~ age_grp2  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
agesheet <- exp(cbind(OR = coef(age), confint.default(age)))
write.csv(agesheet, "age OR regression results controlled urbanunivariable reg women onlypoisson.csv")

age_reg <-summary(age)
write.csv(age_reg, "age p-Value controlled urbanunivariable reg women onlypoisson.csv")

wealth <- glm.cluster(formula = htn_controlled_dbl ~ wealth_quintile_rurb  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
wealthsheet <- exp(cbind(OR = coef(wealth), confint.default(wealth)))
write.csv(wealthsheet, "wealth OR regression results controlled urban univariable reg women onlypoisson.csv")

wealth_reg <-summary(wealth)
write.csv(wealth_reg, "wealth p-Value controlled urbanunivariable reg women onlypoisson.csv")

educat <- glm.cluster(formula = htn_controlled_dbl ~ educatnames  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
educatsheet <- exp(cbind(OR = coef(educat), confint.default(educat)))
write.csv(educatsheet, "educat OR regression results controlled urbanunivariable reg women onlypoisson.csv")

educat_reg <-summary(educat)
write.csv(educat_reg, "educat p-Value controlled urbanunivariable reg women onlypoisson.csv")

married <- glm.cluster(formula = htn_controlled_dbl ~ married + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
marriedsheet <- exp(cbind(OR = coef(married), confint.default(married)))
write.csv(marriedsheet, "married OR regression results controlled urbanunivariable reg women onlypoisson.csv")

married_reg <-summary(married)
write.csv(married_reg, "married p-Value controlled urbanunivariable reg women onlypoisson.csv")

sex <- glm.cluster(formula = htn_controlled_dbl ~ sex  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
sexsheet <- exp(cbind(OR = coef(sex), confint.default(sex)))
write.csv(sexsheet, "sex OR regression results controlled urbanunivariable reg women onlypoisson.csv")

sex_reg <-summary(sex)
write.csv(sex_reg, "sex p-Value controlled urbanunivariable reg women onlypoisson.csv")

bmi <- glm.cluster(formula = htn_controlled_dbl ~ bmi_group  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
bmisheet <- exp(cbind(OR = coef(bmi), confint.default(bmi)))
write.csv(bmisheet, "bmi OR regression results controlled urbanunivariable reg women onlypoisson.csv")

bmi_reg <-summary(bmi)
write.csv(bmi_reg, "bmi p-Value controlled urbanunivariable reg women onlypoisson.csv")

tobacco_smoked <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smoked  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokedsheet <- exp(cbind(OR = coef(tobacco_smoked), confint.default(tobacco_smoked)))
write.csv(tobacco_smokedsheet, "tobacco_smoked OR regression results controlled urbanunivariable reg women onlypoisson.csv")

tobacco_smoked_reg <-summary(tobacco_smoked)
write.csv(tobacco_smoked_reg, "tobacco_smoked p-Value controlled urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless <- glm.cluster(formula = htn_controlled_dbl ~ tobacco_smokeless  + d_id   , cluster="psu", data=dhs_nomiss_htn_only_urban_women, family=poisson(link="log"))
tobacco_smokelesssheet <- exp(cbind(OR = coef(tobacco_smokeless), confint.default(tobacco_smokeless)))
write.csv(tobacco_smokelesssheet, "tobacco_smokeless OR regression results controlled urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless_reg <-summary(tobacco_smokeless)
write.csv(tobacco_smokeless_reg, "tobacco_smokeless p-Value controlled urbanunivariable reg women onlypoisson.csv")





#fast

#multiv_fe <- speedglm(formula = ex_htn_broad_ind ~ sex + age_grp2 + married + wealth_quintile_rurb + educat + urban + d_id, data=dhs_nomiss, family=poisson(link="log"))
#exp(cbind(OR = coef(multiv_fe), confint(multiv_fe)))[2:600,]


```

```{r univariable regressions automatised output}

#######SCREENED RURAL

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked OR regression results screened ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked p-Value screened ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened rural.csv")




#######SCREENED urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results screened urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value screened urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened urban.csv")






#######aware rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware rural.csv")







#######aware urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware urban.csv")




#######treated rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated rural.csv")




#######treated urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated urban.csv")







#######controlled rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled ruralunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled ruralunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled rural univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled ruralunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled ruralunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled ruralunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled ruralunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled ruralunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled ruralunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled ruralunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled ruralunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled ruralunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled ruralunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled ruralunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled ruralunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled ruralunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled rural.csv")










#######controlled urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled urbanunivariable regpoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled urbanunivariable regpoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled urban univariable regpoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled urbanunivariable regpoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled urbanunivariable regpoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled urbanunivariable regpoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled urbanunivariable regpoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled urbanunivariable regpoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled urbanunivariable regpoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled urbanunivariable regpoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled urbanunivariable regpoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled urbanunivariable regpoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled urbanunivariable regpoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled urbanunivariable regpoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled urbanunivariable regpoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled urbanunivariable regpoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled urban.csv")











```


```{r univariable regressions automatised output WEIGHTS}

#######SCREENED RURAL

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened ruralunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened rural univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened ruralunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened ruralunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened ruralunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened ruralunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked OR regression results screened ruralunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened rural weights.csv")




#######SCREENED urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened urbanunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened urban univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened urbanunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened urbanunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened urbanunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened urbanunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results screened urbanunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened urban weights.csv")






#######aware rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware ruralunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware rural univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware ruralunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware ruralunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware ruralunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware ruralunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware ruralunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware rural weights.csv")







#######aware urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware urbanunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware urban univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware urbanunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware urbanunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware urbanunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware urbanunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware urbanunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware urban weights.csv")




#######treated rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated ruralunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated rural univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated ruralunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated ruralunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated ruralunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated ruralunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated ruralunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated rural weights.csv")




#######treated urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated urbanunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated urban univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated urbanunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated urbanunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated urbanunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated urbanunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated urbanunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated urban weights.csv")







#######controlled rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled ruralunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled rural univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled ruralunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled ruralunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled ruralunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled ruralunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled ruralunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled ruralunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled ruralunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled rural weights.csv")










#######controlled urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled urbanunivariable reg with weightspoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled urban univariable reg with weightspoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled urbanunivariable reg with weightspoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled urbanunivariable reg with weightspoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled urbanunivariable reg with weightspoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled urbanunivariable reg with weightspoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled urbanunivariable reg with weightspoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled urbanunivariable reg with weightspoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled urbanunivariable reg with weightspoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled urban weights.csv")











```


```{r univariable regressions automatised output Women}

#######SCREENED RURAL

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened ruralunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened rural univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened ruralunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened ruralunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened ruralunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened ruralunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked OR regression results screened ruralunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened rural women.csv")




#######SCREENED urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened urbanunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened urban univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened urbanunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened urbanunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened urbanunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened urbanunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results screened urbanunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened urban women.csv")






#######aware rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware ruralunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware rural univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware ruralunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware ruralunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware ruralunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware ruralunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware ruralunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware rural women.csv")







#######aware urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware urbanunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware urban univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware urbanunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware urbanunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware urbanunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware urbanunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware urbanunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware urban women.csv")




#######treated rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated ruralunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated rural univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated ruralunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated ruralunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated ruralunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated ruralunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated ruralunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated rural women.csv")




#######treated urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated urbanunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated urban univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated urbanunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated urbanunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated urbanunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated urbanunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated urbanunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated urban women.csv")







#######controlled rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled ruralunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled rural univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled ruralunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled ruralunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled ruralunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled ruralunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled ruralunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled ruralunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled ruralunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled rural women.csv")










#######controlled urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled urbanunivariable reg women onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled urban univariable reg women onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled urbanunivariable reg women onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled urbanunivariable reg women onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled urbanunivariable reg women onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled urbanunivariable reg women onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled urbanunivariable reg women onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled urbanunivariable reg women onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled urbanunivariable reg women onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled urban women.csv")











```







```{r univariable regressions automatised output men}

#######SCREENED RURAL

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened ruralunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened rural univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened ruralunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened ruralunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened ruralunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened ruralunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked OR regression results screened ruralunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco smoked p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened rural men.csv")




#######SCREENED urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results screened urbanunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results screened urban univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results screened urbanunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results screened urbanunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results screened urbanunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results screened urbanunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results screened urbanunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results screened urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value screened urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni screened urban men.csv")






#######aware rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware ruralunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware rural univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware ruralunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware ruralunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware ruralunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware ruralunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware ruralunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware rural men.csv")







#######aware urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results aware urbanunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results aware urban univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results aware urbanunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results aware urbanunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results aware urbanunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results aware urbanunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results aware urbanunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results aware urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value aware urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni aware urban men.csv")




#######treated rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated ruralunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated rural univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated ruralunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated ruralunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated ruralunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated ruralunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated ruralunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated rural men.csv")




#######treated urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results treated urbanunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results treated urban univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results treated urbanunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results treated urbanunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results treated urbanunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results treated urbanunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results treated urbanunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results treated urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value treated urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni treated urban men.csv")







#######controlled rural

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled ruralunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled rural univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled ruralunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled ruralunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled ruralunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled ruralunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled ruralunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled ruralunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled ruralunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled rural men.csv")










#######controlled urban

age <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age OR regression results controlled urbanunivariable reg men onlypoisson.csv")

age1<-age[c(2,3,4,5,6,7), ]

age_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/age p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-age_p[c(2,3,4,5,6,7),5 ]

age_final<-cbind(age1,p1)

age_final <- mutate(age_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


age_final <- mutate(age_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

wealth<- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth OR regression results controlled urban univariable reg men onlypoisson.csv")

wealth1<-wealth[c(2,3,4,5), ]

wealth_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/wealth p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-wealth_p[c(2,3,4,5),5 ]

wealth_final<-cbind(wealth1,p1)

wealth_final <- mutate(wealth_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


wealth_final <- mutate(wealth_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

educat <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat OR regression results controlled urbanunivariable reg men onlypoisson.csv")

educat1<-educat[c(2,3,4), ]

educat_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/educat p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-educat_p[c(2,3,4),5 ]

educat_final<-cbind(educat1,p1)

educat_final <- mutate(educat_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


educat_final <- mutate(educat_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

married <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married OR regression results controlled urbanunivariable reg men onlypoisson.csv")

married1<-married[c(2), ]

married_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/married p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-married_p[c(2),5 ]

married_final<-cbind(married1,p1)

married_final <- mutate(married_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


married_final <- mutate(married_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

sex <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex OR regression results controlled urbanunivariable reg men onlypoisson.csv")

sex1<-sex[c(2), ]

sex_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/sex p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-sex_p[c(2),5 ]

sex_final<-cbind(sex1,p1)

sex_final <- mutate(sex_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


sex_final <- mutate(sex_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

bmi <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi OR regression results controlled urbanunivariable reg men onlypoisson.csv")

bmi1<-bmi[c(2,3,4,5,6), ]

bmi_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/bmi p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-bmi_p[c(2,3,4,5,6),5 ]

bmi_final<-cbind(bmi1,p1)

bmi_final <- mutate(bmi_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


bmi_final <- mutate(bmi_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))



tobacco_smoked <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked OR regression results controlled urbanunivariable reg men onlypoisson.csv")

tobacco_smoked1<-tobacco_smoked[c(2), ]

tobacco_smoked_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smoked p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smoked_p[c(2),5 ]

tobacco_smoked_final<-cbind(tobacco_smoked1,p1)

tobacco_smoked_final <- mutate(tobacco_smoked_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smoked_final <- mutate(tobacco_smoked_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))

tobacco_smokeless <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless OR regression results controlled urbanunivariable reg men onlypoisson.csv")

tobacco_smokeless1<-tobacco_smokeless[c(2), ]

tobacco_smokeless_p <- read.csv("~/Documents/Public Health Files/Public Health/public health/hypertension/Hypertension no50to54men/tobacco_smokeless p-Value controlled urbanunivariable reg men onlypoisson.csv")

p1<-tobacco_smokeless_p[c(2),5 ]

tobacco_smokeless_final<-cbind(tobacco_smokeless1,p1)

tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                OR = format(round(OR, digits=2), nsmall = 2),
                X2.5.. = format(round(X2.5.., digits=2), nsmall = 2),
                X97.5.. = format(round(X97.5.., digits=2), nsmall = 2),
                p1 = format(round(p1, digits=3), nsmall = 3))


tobacco_smokeless_final <- mutate(tobacco_smokeless_final,
                p1 = ifelse(p1=="0.000","<0.001",p1))


Final <- rbind(age_final,educat_final)
Final <- rbind(Final,wealth_final)
Final <- rbind(Final,bmi_final)
Final <- rbind(Final,tobacco_smoked_final)
Final <- rbind(Final,tobacco_smokeless_final)
Final <- rbind(Final,married_final)
Final <- rbind(Final,sex_final)

library(DataCombine)

Reff <- c(" ", "1 (Reference)"," "," "," ")
noref <- c(" "," "," "," "," ")


Final <- InsertRow(Final, NewRow = Reff, RowNum = 15)
Final <- InsertRow(Final, NewRow = noref, RowNum = 14)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 10)
Final <- InsertRow(Final, NewRow = noref, RowNum = 10)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 7)
Final <- InsertRow(Final, NewRow = noref, RowNum = 7)
Final <- InsertRow(Final, NewRow = Reff, RowNum = 1)
Final <- InsertRow(Final, NewRow = noref, RowNum = 1)

write.csv(Final,"uni controlled urban men.csv")











```









```{r regression figure  education}

#Regression figure for hypertension education#

dhs_nomiss_regress <- filter(dhs_nomiss, is.na(ex_htn_narrow_ind)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                               is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_regress <- augment(multiv_feglm, dhs_nomiss, type.predict = "response", se.fit = TRUE)


dhs_nomiss_regress <- dhs_nomiss_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


#Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "educatnames", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))
write.csv(fig4.htn, "regressionfigure_htn_educat.csv")

#Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(educat=="x" | educat=="x", lowerci, NA),
         upperci_alt=ifelse(educat=="x" | educat=="x", upperci, NA),
         alphaindic = as.factor(ifelse(educat=="x" | educat=="x", 1, 0)))


#Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=educatnames, shape=educatnames), fun.y="mean", size=3.0, geom="point") +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 50), ratio= 8/40, expand=T) +
  theme_classic() +
  labs(x = "Age group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Education") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Education") 
htnpredfig

#Regression figure for screened education #

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_feglmscreened, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "educatnames", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_educat htn 3 28.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(educatnames=="Highschool unfinished" | educatnames=="Highschool or above", lowerci, NA),
         upperci_alt=ifelse(educatnames=="Highschool unfinished" | educatnames=="Highschool or above", upperci, NA),
         alphaindic = as.factor(ifelse(educatnames=="Highschool unfinished" | educatnames=="Highschool or above", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=educatnames, shape=educatnames), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=educatnames), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 70), ratio= 8/50, expand=T) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Education") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Education") 
htnpredfig

dev.copy(pdf,'reg screened education htn.pdf')
dev.off()


#Regression figure for aware education #

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_feglmaware, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "educatnames", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_educat htn 3 28.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(educatnames=="Highschool unfinished" | educatnames=="Highschool or above", lowerci, NA),
         upperci_alt=ifelse(educatnames=="Highschool unfinished" | educatnames=="Highschool or above", upperci, NA),
         alphaindic = as.factor(ifelse(educatnames=="Highschool unfinished" | educatnames=="Highschool or above", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=educatnames, shape=educatnames), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=educatnames), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 70), ratio= 8/50, expand=T) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Education") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Education") 
htnpredfig

dev.copy(pdf,'reg aware education htn.pdf')
dev.off()


#Regression figure for treated education #




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_feglmtreated, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "educatnames", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated educat htn 3 28.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(educatnames=="x" | educatnames=="x", lowerci, NA),
         upperci_alt=ifelse(educatnames=="x" | educatnames=="x", upperci, NA),
         alphaindic = as.factor(ifelse(educatnames=="x" | educatnames=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=educatnames, shape=educatnames), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=educatnames), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 30), ratio= 8/30, expand=T) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Education") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Education") 
htnpredfig

dev.copy(pdf,'reg treated education htn.pdf')
dev.off()

#Regression figure for controlled education#



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_feglmcontrolled, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + educatnames + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "educatnames", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled educat 3 28.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(educatnames=="x" | educatnames=="x", lowerci, NA),
         upperci_alt=ifelse(educatnames=="x" | educatnames=="x", upperci, NA),
         alphaindic = as.factor(ifelse(educatnames=="x" | educatnames=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=educatnames, shape=educatnames), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=educatnames), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 30), ratio= 8/20, expand=T) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Education") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Education") 
htnpredfig


dev.copy(pdf,'reg controlled education htn.pdf')
dev.off()


```

```{r regression figure wealth}


#######regression figure htn wealth##########################


dhs_nomiss_regress <- filter(dhs_nomiss, is.na(ex_htn_narrow_ind)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                               is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_regress <- augment(multiv_feglm, dhs_nomiss, type.predict = "response", se.fit = TRUE)


dhs_nomiss_regress <- dhs_nomiss_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


#Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))
write.csv(fig4.htn, "regressionfigure_htn_wealth.csv")

#Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="Q (Richest)" | wealth_quintile_rurb_lab=="Q (Poorest)", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="Q (Richest)" | wealth_quintile_rurb_lab=="Q (Poorest)", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="Q (Richest)" | wealth_quintile_rurb_lab=="Q (Poorest)", 1, 0)))


#Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 50), ratio= 8/40, expand=T) +
  theme_classic() +
  labs(x = "Age group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth quintile") 
htnpredfig


##############Regression figure for screened wealth quintile################################

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_feglmscreened, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn no weights 5 16.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 7/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



##############Regression figure for aware wealth quintile################################

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_feglmaware, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn no weights 5 16.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 7/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


##############Regression figure for treated wealth################################




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_feglmtreated, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn no weights 5 16.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 7/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

##############Regression figure for controlled wealth quintile ################################



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_feglmcontrolled, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth no weights 5 16.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 7/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```



```{r regression figure SIMPLE}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_feglmscreened, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_feglmaware, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_feglmtreated, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_feglmcontrolled, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```




```{r regression figure WEIGHTS}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_weight_feglmscreened, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn WEIGHTS.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_weight_feglmaware, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn WEIGHTS.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_weight_feglmtreated, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn WEIGHTS.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_weight_feglmcontrolled, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth WEIGHTS.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```


```{r regression figure Women}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_women_feglmscreened, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn WOMEN.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_women_feglmaware, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn WOMEN.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_women_feglmtreated, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn WOMEN.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_women_feglmcontrolled, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth WOMEN.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```




```{r regression figure MEN}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_men_feglmscreened, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn MEN.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_men_feglmaware, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn MEN.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_men_feglmtreated, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn MEN.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_men_feglmcontrolled, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth MEN.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```





```{r regression figure SPLINE SIMPLE NO WEIGHTS}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_feclust_screened_htn555noweights, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn spline SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_feclust_aware_htn555noweights, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn spline SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_feclust_treated_htn555noweights, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn spline SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_feclust_controlled_htn555noweights, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth spline SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```








```{r regression figure SPLINE WEIGHTS}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_screened_regress <- filter(dhs_nomiss_htn_only, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_screened_regress <- augment(multiv_feclust_screened_htn555, dhs_nomiss_htn_only_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_screened_regress <- dhs_nomiss_htn_only_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_aware_regress <- filter(dhs_nomiss_htn_only, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_aware_regress <- augment(multiv_feclust_aware_htn555, dhs_nomiss_htn_only_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_aware_regress <- dhs_nomiss_htn_only_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_treated_regress <- filter(dhs_nomiss_htn_only, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_treated_regress <- augment(multiv_feclust_treated_htn555, dhs_nomiss_htn_only_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_treated_regress <- dhs_nomiss_htn_only_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_controlled_regress <- filter(dhs_nomiss_htn_only, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_controlled_regress <- augment(multiv_feclust_controlled_htn555, dhs_nomiss_htn_only_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_controlled_regress <- dhs_nomiss_htn_only_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```





```{r regression figure SPLINE Women}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_women_screened_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_women_screened_regress <- augment(multiv_feclust_screened_htn555women, dhs_nomiss_htn_only_women_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_women_screened_regress <- dhs_nomiss_htn_only_women_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_women_aware_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_women_aware_regress <- augment(multiv_feclust_aware_htn555women, dhs_nomiss_htn_only_women_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_women_aware_regress <- dhs_nomiss_htn_only_women_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_women_treated_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_women_treated_regress <- augment(multiv_feclust_treated_htn555women, dhs_nomiss_htn_only_women_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_women_treated_regress <- dhs_nomiss_htn_only_women_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_women_controlled_regress <- filter(dhs_nomiss_htn_only_women, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_women_controlled_regress <- augment(multiv_feclust_controlled_htn555women, dhs_nomiss_htn_only_women_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_women_controlled_regress <- dhs_nomiss_htn_only_women_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_women_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```







```{r regression figure SPLINE men}

#Regression figure for screened wealth quintile#

dhs_nomiss_htn_only_men_screened_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_screened_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                              is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_men_screened_regress <- augment(multiv_feclust_screened_htn555men, dhs_nomiss_htn_only_men_screened_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_men_screened_regress <- dhs_nomiss_htn_only_men_screened_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_screened_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_screened_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                   lowerci = prob_htn-(1.96*se_htn),
                   upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_screened_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg screened wealth htn 3 28.pdf')
dev.off()



#Regression figure for aware wealth quintile#

dhs_nomiss_htn_only_men_aware_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_aware_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                   is.na(wealth_quintile_rurb_lab)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_men_aware_regress <- augment(multiv_feclust_aware_htn555men, dhs_nomiss_htn_only_men_aware_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_men_aware_regress <- dhs_nomiss_htn_only_men_aware_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_aware_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_aware_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))


write.csv(fig4.htn, "regressionfigure_aware_wealth htn SIMPLE.csv")


# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg aware wealth htn 9 5.pdf')
dev.off()


#Regression figure for treated wealth#




dhs_nomiss_htn_only_men_treated_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_treated_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                     is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_men_treated_regress <- augment(multiv_feclust_treated_htn555men, dhs_nomiss_htn_only_men_treated_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_men_treated_regress <- dhs_nomiss_htn_only_men_treated_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_treated_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_treated_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_treated wealth htn SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

dev.copy(pdf,'reg treated wealth htn 3 28.pdf')
dev.off()

#Regression figure for controlled wealth quintile #



dhs_nomiss_htn_only_men_controlled_regress <- filter(dhs_nomiss_htn_only_men, is.na(htn_controlled_dbl)==FALSE  & is.na(sex)==FALSE & is.na(age_grpOR)==FALSE & is.na(married)==FALSE & 
                                                        is.na(wealth_quintile_rurb)==FALSE & is.na(educat)==FALSE & is.na(urban)==FALSE & is.na(d_id)==F)
dhs_nomiss_htn_only_men_controlled_regress <- augment(multiv_feclust_controlled_htn555men, dhs_nomiss_htn_only_men_controlled_regress, type.predict = "response", se.fit = TRUE)


dhs_nomiss_htn_only_men_controlled_regress <- dhs_nomiss_htn_only_men_controlled_regress %>% 
  mutate(prob_htn = .fitted,
         se_htn = .se.fit) %>% 
  dplyr::select(-.resid, -.hat, -.sigma, -.cooksd, -.std.resid, -.fitted, -.se.fit)


# Create dataset for plotting
pmeans_htn <- aggregate(prob_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_controlled_regress, FUN = mean)
p_standerr_htn <- aggregate(se_htn ~ age_grpOR + wealth_quintile_rurb_lab + urban_lab, data = dhs_nomiss_htn_only_men_controlled_regress, FUN = mean)
fig4.htn <- left_join(pmeans_htn, p_standerr_htn, by = c("age_grpOR", "wealth_quintile_rurb_lab", "urban_lab"))
fig4.htn <- mutate(fig4.htn, 
                    lowerci = prob_htn-(1.96*se_htn),
                    upperci = prob_htn+(1.96*se_htn))

write.csv(fig4.htn, "regressionfigure_controlled wealth SIMPLE.csv")



# Set errors bars for wealth quintiles 2, 3 and 4 to zero
fig4.htn <- fig4.htn %>% 
  mutate(lowerci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", lowerci, NA),
         upperci_alt=ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", upperci, NA),
         alphaindic = as.factor(ifelse(wealth_quintile_rurb_lab=="x" | wealth_quintile_rurb_lab=="x", 1, 0)))


# Draw the actual figure
brightness <- function(rgbcol, v) {
  conv <- as.list(as.data.frame(t(rgb2hsv(col2rgb(rgbcol)))))
  conv[[3]] <- v
  do.call(hsv, conv)
}

htnpredfig <- fig4.htn %>% 
  ggplot() +
  stat_summary(aes(y=100*prob_htn, x=age_grpOR, color=wealth_quintile_rurb_lab, shape=wealth_quintile_rurb_lab), fun.y="mean", size=3.0, geom="point") +
  geom_errorbar(aes(ymin=100*lowerci_alt, ymax=100*upperci_alt, x=age_grpOR, color=wealth_quintile_rurb_lab), width=0.3, show.legend = F) +
  facet_wrap(~urban_lab) +
  coord_fixed(ylim=c(0, 100), ratio= 6/100, expand=F) +
  theme_classic() +
  labs(x = "Age Group, y",
       y = "Probability, %",
       fill="") +
  theme(axis.text.y=element_text(size=18, family="Times"),
        axis.text.x=element_text(size=18, angle=45, hjust=1, family="Times"),
        axis.title=element_text(size=21, face="bold", family="Times"),
        legend.title=element_text(size=18, family="Times"),
        legend.text=element_text(size=18, family="Times"),
        strip.text=element_text(size=18, family="Times"), 
        panel.spacing = unit(2.5, "lines"),
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        plot.title = element_text(size=24, face="bold", family="Times"))+
  scale_colour_manual(values = brightness("red", seq(0.0, 1.0, length = 5)), name="Household Wealth Quintile") +
  scale_shape_manual(values = c(19, 25, 22, 23, 17), name="Household Wealth Quintile") 
htnpredfig

show(htnpredfig)

dev.copy(pdf,'controlled.pdf')
dev.off()



```






```{prevalence estimates sex and state}

####### crude htn prev by sex and state
svy_tot <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind, female_lab, ex_state_ind))

prevtot <- svy_tot %>%
group_by(female_lab, ex_state_ind) %>% 
  summarise(htn_prop = survey_mean(ex_htn_broad_ind, proportion=TRUE, vartype = "ci")) %>%
  mutate(htn = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)

write_csv(prevtot, "stateprevhtnbysexandstate_2018-03_22.csv")





##### Crude controlled htn prev by sex and state

svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, female_lab, ex_state_ind))

prevtot <- svy_controlled %>%
  group_by(female_lab, ex_state_ind) %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "stateprevcontrolledsexandstate_2018-03_22.csv")

#### Crude treated htn prev by sex and state


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, female_lab, ex_state_ind))

prevtot <- svy_treated %>%
  group_by(female_lab, ex_state_ind) %>% 
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "stateprevtreatedbysexandstate_2018-03-02.csv")

#### Crude aware htn prev by sex and state


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, female_lab, ex_state_ind))

prevtot <- svy_aware %>%
  group_by(female_lab, ex_state_ind) %>% 
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "stateprevawarebysexandstate_2018-03_22.csv")

#### Crude screened htn prev by sex and state


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, female_lab, ex_state_ind))

prevtot <- svy_screened %>%
  group_by(female_lab, ex_state_ind) %>% 
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "stateprevscreenedbysexandstate_2018-03_22.csv")

```

```{r prevalence by sex nfhs definition only with old weights}

dhs_nomiss <-mutate(dhs_nomiss,
             ex_htn_nfhs4_ind = ifelse(is.na(ex_htn_narrow_ind)==T | is.na(hypt) ==T | is.na(hypt_med)==T, NA,ifelse(hypt_med==1  | ex_htn_narrow_ind==1, 1, 0)))

dhs_nomiss$ex_htn_nfhs4_ind_dbl <- as.numeric(dhs_nomiss$ex_htn_nfhs4_ind)

dhs_nomiss_noNAinpsu <- filter(dhs_nomiss, is.na(psu)==F)


####### crude htn prev by sex 
svy_tot <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(ex_htn_nfhs4_ind_dbl, female_lab))

prevtot <- svy_tot %>%
  group_by(female_lab) %>% 
  summarise(htn_prop = survey_mean(ex_htn_nfhs4_ind_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)

write_csv(prevtot, "stateprevhtnbysexonly  nfhs4 def _2018-03_22.csv")


```

```{r prevalence in age group 15-29}

dhs_nomiss1529 <- filter(dhs_nomiss, age<30)

dhs_nomiss_noNAinpsu1529 <- filter(dhs_nomiss1529, is.na(psu)==F)


####### crude htn prev by sex 
svy_tot <- dhs_nomiss_noNAinpsu1529 %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind))

prevtot <- svy_tot %>%
  summarise(htn_prop = survey_mean(ex_htn_broad_ind, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)

write_csv(prevtot, "stateprevhtn 15 to 29.csv")

```



```{r prevalence by sex}




####### crude htn prev by sex 
svy_tot <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind, female_lab, ex_state_ind))

prevtot <- svy_tot %>%
  group_by(female_lab) %>% 
  summarise(htn_prop = survey_mean(ex_htn_broad_ind, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)

write_csv(prevtot, "stateprevhtnbysexonly_2018-03_22.csv")

##### Crude controlled htn prev by sex

svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, female_lab, ex_state_ind))

prevtot <- svy_controlled %>%
  group_by(female_lab) %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "htnstateprevcontrolledsexonly_2018-03_22.csv")

#### Crude treated htn prev by sex 


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, female_lab, ex_state_ind))

prevtot <- svy_treated %>%
  group_by(female_lab) %>% 
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnstateprevtreatedbysexonly_2018-03_22.csv")

#### Crude aware htn prev by sex 


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, female_lab, ex_state_ind))

prevtot <- svy_aware %>%
  group_by(female_lab) %>% 
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "htnstateprevawarebysexonly_2018-03_22.csv")


#### Crude screened htn prev by sex 


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, female_lab, ex_state_ind))

prevtot <- svy_screened %>%
  group_by(female_lab) %>% 
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "htnstateprevscreenedbysexonly_2018-03_22.csv")

```

```{r prevalence by sex and age}

####### crude htn prev by sex and age 
svy_tot <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind,age_grp2, female_lab, ex_state_ind, ex_htn_broad_ind))

prevtot <- svy_tot %>%
  group_by(female_lab, age_grp2) %>% 
  summarise(htn_prop = survey_mean(ex_htn_broad_ind, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)

write_csv(prevtot, "htnstateprevhtnbysexandage_2018-03_22.csv")

##### Crude controlled htn prev by sex and age

svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, age_grp2, female_lab, ex_state_ind))

prevtot <- svy_controlled %>%
  group_by(female_lab, age_grp2) %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "htnstateprevcontrolledsexandage_2018-03-10.csv")

#### Crude treated htn prev by sex and age


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, age_grp2, female_lab, ex_state_ind))

prevtot <- svy_treated %>%
  group_by(female_lab, age_grp2) %>% 
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnstateprevtreatedbysexandage_2018-03-10.csv")

#### Crude aware htn prev by sex and age 


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, age_grp2, female_lab, ex_state_ind))

prevtot <- svy_aware %>%
  group_by(female_lab, age_grp2) %>% 
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "htnstateprevawarebysexandage_2018-03-10.csv")

#### Crude screened htn prev by sex and age 


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, age_grp2, female_lab, ex_state_ind))

prevtot <- svy_screened %>%
  group_by(female_lab, age_grp2) %>% 
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "htnstateprevscreenedbysexandage_2018-03-10.csv")


```

```{r prevalence among aware by sex}


#####Crude prevalence of treated among aware htns group by sex


svy_aware <- dhs_nomiss_htn_and_aware_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, female_lab, ex_state_ind))

prevtot <- svy_aware %>%
  group_by(female_lab) %>% 
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreatedofawarebysex_2018-03_22.csv")

```

```{r prevalence among treated by sex}

######Crude prevalence of controlled among treated htns by sex

svy_aware <- dhs_nomiss_htn_and_treated_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, female_lab, ex_state_ind))

prevtot <- svy_aware %>%
  group_by(female_lab) %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)


write_csv(prevtot, "htnprevcontrolledoftreatedbysex_2018-03_22.csv")


```

```{r prevalence among aware}
#####Crude prevalence of treated among aware htns group 


svy_aware <- dhs_nomiss_htn_and_aware_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl  ))

prevtot <- svy_aware %>% 
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreatedofaware_2018-03-09.csv")


######Crude prevalence of controlled among treated htns 

svy_aware <- dhs_nomiss_htn_and_treated_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl))

prevtot <- svy_aware %>%
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)


write_csv(prevtot, "htnprevcontrolledoftreated_2018-03-09.csv")

```

```{r prevalence cascade crude}

##### Crude controlled htn prev 

svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl))

prevtot <- svy_controlled %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "htnprevcontrolled_2018-03_22.csv")

#### Crude treated htn prev 


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl))

prevtot <- svy_treated %>%
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreated_2018-03_22.csv")

#### Crude aware htn prev  


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl))

prevtot <- svy_aware %>%
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "htnprevaware_2018-03_22.csv")

#### Crude screened htn prev  


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl))

prevtot <- svy_screened %>%
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "htnprevscreened_2018-03_22.csv")

```





```{r prevalence cascade crude WITH SAMPLING WEIGHTS THAT DONT ADJUST FOR MEN WOMEN DIFFERENCE}

##### Crude controlled htn prev 

svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_controlled_dbl))

prevtot <- svy_controlled %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "htnprevcontrolled_2018-03_22old sampling weights that dont adjust for low number men.csv")

#### Crude treated htn prev 


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_treated_dbl))

prevtot <- svy_treated %>%
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreated_2018-03_22old sampling weights that dont adjust for low number men.csv")

#### Crude aware htn prev  


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_aware_dbl))

prevtot <- svy_aware %>%
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "htnprevaware_2018-03_22old sampling weights that dont adjust for low number men.csv")

#### Crude screened htn prev  


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_screened_dbl))

prevtot <- svy_screened %>%
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "htnprevscreened_2018-03_22old sampling weights that dont adjust for low number men.csv")

```





```{r prevalence cascade crude WITH SAMPLING WEIGHTS THAT DONT ADJUST FOR MEN WOMEN DIFFERENCE AND NFHS4 definition}


dhs_nomiss <-mutate(dhs_nomiss,
             ex_htn_nfhs4_ind = ifelse(is.na(ex_htn_narrow_ind)==T | is.na(hypt) ==T | is.na(hypt_med)==T, NA,ifelse(hypt_med==1  | ex_htn_narrow_ind==1, 1, 0)))

dhs_nomiss$ex_htn_nfhs4_ind_dbl <- as.numeric(dhs_nomiss$ex_htn_nfhs4_ind)

dhs_nomiss_noNAinpsu <- filter(dhs_nomiss, is.na(psu)==F)


########################  CREATE HTN Subgroups  #################################################

#filter htn only
dhs_nomiss_htn_only_nfhs4def <- filter(dhs_nomiss, (ex_htn_nfhs4_ind)==1) 


##screened htn

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     htn_screened = bp_ms)

dhs_nomiss_htn_only_nfhs4def$htn_screened <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_screened)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                              
                              htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_screened)


##aware htn


##aware htn as subset of htn



dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     htn_aware = ifelse(hypt==1 | hypt_med==1, 1, 0))


dhs_nomiss_htn_only_nfhs4def$htn_aware <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_aware)



dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_aware)

##treated htn as subset of htns


dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                   htn_treated = ifelse(hypt_med==1, 1, 0))
#dhs_nomiss_htn_only_nfhs4def[which(is.na(dhs_nomiss_htn_only_nfhs4def$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss_htn_only_nfhs4def$htn_treated <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_treated)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                   
                                   htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                             htn_controlled = ifelse((hypt_med==1 & ex_htn_narrow_ind==0), 1, 0))

dhs_nomiss_htn_only_nfhs4def$htn_controlled <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_controlled)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                             
                                             htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_controlled)


dhs_nomiss_htn_only_nfhs4def_noNAinpsu <- filter(dhs_nomiss_htn_only_nfhs4def, is.na(psu)==F)





##### Crude controlled htn prev 

svy_controlled <- dhs_nomiss_htn_only_nfhs4def_noNAinpsuu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_controlled_dbl))

prevtot <- svy_controlled %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "htnprevcontrolled_2018-03_22old sampling weights that dont adjust for low number mennfhs4 definition.csv")

#### Crude treated htn prev 


svy_treated <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_treated_dbl))

prevtot <- svy_treated %>%
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreated_2018-03_22old sampling weights that dont adjust for low number mennfhs4 definition.csv")

#### Crude aware htn prev  


svy_aware <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_aware_dbl))

prevtot <- svy_aware %>%
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "htnprevaware_2018-03_22old sampling weights that dont adjust for low number mennfhs4 definition.csv")

#### Crude screened htn prev  


svy_screened <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt,
                   variables = c(htn_screened_dbl))

prevtot <- svy_screened %>%
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "htnprevscreened_2018-03_22old sampling weights that dont adjust for low number mennfhs4 definition.csv")

```



```{r prevalence cascade crude WITH SAMPLING WEIGHTS THAT DONT ADJUST FOR MEN WOMEN DIFFERENCE AND NFHS4 definition}


dhs_nomiss <-mutate(dhs_nomiss,
             ex_htn_nfhs4_ind = ifelse(is.na(ex_htn_narrow_ind)==T | is.na(hypt) ==T | is.na(hypt_med)==T, NA,ifelse(hypt_med==1  | ex_htn_narrow_ind==1, 1, 0)))

dhs_nomiss$ex_htn_nfhs4_ind_dbl <- as.numeric(dhs_nomiss$ex_htn_nfhs4_ind)

dhs_nomiss_noNAinpsu <- filter(dhs_nomiss, is.na(psu)==F)


########################  CREATE HTN Subgroups  #################################################

#filter htn only
dhs_nomiss_htn_only_nfhs4def <- filter(dhs_nomiss, (ex_htn_nfhs4_ind)==1) 


##screened htn

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     htn_screened = bp_ms)

dhs_nomiss_htn_only_nfhs4def$htn_screened <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_screened)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                              
                              htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_screened)


##aware htn


##aware htn as subset of htn



dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     htn_aware = ifelse(hypt==1 | hypt_med==1, 1, 0))


dhs_nomiss_htn_only_nfhs4def$htn_aware <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_aware)



dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_aware)

##treated htn as subset of htns


dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                   htn_treated = ifelse(hypt_med==1, 1, 0))
#dhs_nomiss_htn_only_nfhs4def[which(is.na(dhs_nomiss_htn_only_nfhs4def$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss_htn_only_nfhs4def$htn_treated <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_treated)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                   
                                   htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                             htn_controlled = ifelse((hypt_med==1 & ex_htn_narrow_ind==0), 1, 0))

dhs_nomiss_htn_only_nfhs4def$htn_controlled <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_controlled)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                             
                                             htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_controlled)


dhs_nomiss_htn_only_nfhs4def_noNAinpsu <- filter(dhs_nomiss_htn_only_nfhs4def, is.na(psu)==F)





#### Crude treated htn prev 


svy_treated <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(hypt_med))

prevtot <- svy_treated %>%
  summarise(htn_treated_prop = survey_mean(hypt_med, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreated with ex_dia_med_ind.csv")


```







```{r prevalence cascade crude NFHS4 definition}


dhs_nomiss <-mutate(dhs_nomiss,
             ex_htn_nfhs4_ind = ifelse(is.na(ex_htn_narrow_ind)==T | is.na(hypt) ==T | is.na(hypt_med)==T, NA,ifelse(hypt_med==1  | ex_htn_narrow_ind==1, 1, 0)))

dhs_nomiss$ex_htn_nfhs4_ind_dbl <- as.numeric(dhs_nomiss$ex_htn_nfhs4_ind)

dhs_nomiss_noNAinpsu <- filter(dhs_nomiss, is.na(psu)==F)


########################  CREATE HTN Subgroups  #################################################

#filter htn only
dhs_nomiss_htn_only_nfhs4def <- filter(dhs_nomiss, (ex_htn_nfhs4_ind)==1) 


##screened htn

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     htn_screened = bp_ms)

dhs_nomiss_htn_only_nfhs4def$htn_screened <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_screened)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                              
                              htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_screened)


##aware htn


##aware htn as subset of htn



dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     htn_aware = ifelse(hypt==1 | hypt_med==1, 1, 0))


dhs_nomiss_htn_only_nfhs4def$htn_aware <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_aware)



dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_aware)

##treated htn as subset of htns


dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                   htn_treated = ifelse(hypt_med==1, 1, 0))
#dhs_nomiss_htn_only_nfhs4def[which(is.na(dhs_nomiss_htn_only_nfhs4def$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss_htn_only_nfhs4def$htn_treated <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_treated)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                   
                                   htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                             htn_controlled = ifelse((hypt_med==1 & ex_htn_narrow_ind==0), 1, 0))

dhs_nomiss_htn_only_nfhs4def$htn_controlled <- as.factor(dhs_nomiss_htn_only_nfhs4def$htn_controlled)

dhs_nomiss_htn_only_nfhs4def <- mutate(dhs_nomiss_htn_only_nfhs4def,
                                             
                                             htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss_htn_only_nfhs4def$htn_controlled)


dhs_nomiss_htn_only_nfhs4def_noNAinpsu <- filter(dhs_nomiss_htn_only_nfhs4def, is.na(psu)==F)


##### Crude controlled htn prev 

svy_controlled <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl))

prevtot <- svy_controlled %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)



write_csv(prevtot, "htnprevcontrollednfhs4def.csv")

#### Crude treated htn prev 


svy_treated <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl))

prevtot <- svy_treated %>%
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "htnprevtreatednfhs4def.csv")

#### Crude aware htn prev  


svy_aware <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl))

prevtot <- svy_aware %>%
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "htnprevawarenfhs4def.csv")

#### Crude screened htn prev  


svy_screened <- dhs_nomiss_htn_only_nfhs4def_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl))

prevtot <- svy_screened %>%
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "htnprevscreenednfhs4def.csv")

```




```{r prevalence by state}
#### Crude htn prev by state


svy_htn <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind_dbl, ex_state_ind))

prevtot <- svy_htn %>%
  group_by(ex_state_ind) %>% 
  summarize(htn_prop = survey_mean(ex_htn_broad_ind_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_ = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)


write_csv(prevtot, "stateprevhtnbystate_2018-04-10.csv")


#### Crude screened htn prev by state


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, ex_state_ind))

prevtot <- svy_screened %>%
  group_by(ex_state_ind) %>% 
  summarize(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "stateprevscreenedbystate_2018-03-08.csv")

#### Crude aware htn prev by state


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, ex_state_ind))

prevtot <- svy_aware %>%
  group_by(ex_state_ind) %>% 
  summarize(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "stateprevawarebystate_2018-03-08.csv")

#### Crude treated htn prev by state


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, ex_state_ind))

prevtot <- svy_treated %>%
  group_by(ex_state_ind) %>% 
  summarize(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "stateprevtreatedbystate_2018-03-08.csv")

#### Crude controlled htn prev by state


svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, ex_state_ind))

prevtot <- svy_controlled %>%
  group_by(ex_state_ind) %>% 
  summarize(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)


write_csv(prevtot, "stateprevcontrolledbystate_2018-03-08.csv")

```

```{r prevalence by state and urbanrural}

#### Crude htn prev by state and urban/rural


svy_htn <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind, urban_lab))

prevtot <- svy_htn %>%
  group_by(urban_lab) %>% 
  summarize(htn_prop = survey_mean(ex_htn_broad_ind, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_ = 100*htn_prop,
         htn_low = 100*htn_prop_low,
         htn_upp = 100*htn_prop_upp)


write_csv(prevtot, "prevhtnbyurbanrural_2018-03-08.csv")

#### Crude screened htn prev by rural/urban


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, urban_lab))

prevtot <- svy_screened %>%
  group_by(urban_lab) %>% 
  summarize(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "prevscreenedbyurbanrural_2018-04-19.csv")


#### Crude aware htn prev by rural/urban


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, urban_lab))

prevtot <- svy_aware %>%
  group_by(urban_lab) %>% 
  summarize(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "prevawarebyurbanrural_2018-04-19.csv")


#### Crude treated htn prev by urban/rural


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, urban_lab))

prevtot <- svy_treated %>%
  group_by(urban_lab) %>% 
  summarize(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "prevtreatedbyurbanrural_2018-04-19.csv")


#### Crude controlled htn prev by urban/rural


svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, urban_lab))

prevtot <- svy_controlled %>%
  group_by(urban_lab) %>% 
  summarize(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)


write_csv(prevtot, "prevcontrolledbyurbanrural_2018-04-19.csv")

```

```{r prevalence hypertension overall}

####Hyp prev overall

svy_diab <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind_dbl))

prevtot <- svy_diab %>%
  summarize(diab_prop = survey_mean(ex_htn_broad_ind_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(diab_ = 100*diab_prop,
         diab_low = 100*diab_prop_low,
         diab_upp = 100*diab_prop_upp)


write_csv(prevtot, "prevhtnoverall_2018-03-08.csv")

```



```{r prevalence hypertension overall when using NFHS4 definition}

dhs_nomiss <-mutate(dhs_nomiss,
             ex_htn_nfhs4_ind = ifelse(is.na(ex_htn_narrow_ind)==T | is.na(hypt) ==T | is.na(hypt_med)==T, NA,ifelse(hypt_med==1  | ex_htn_narrow_ind==1, 1, 0)))

dhs_nomiss$ex_htn_nfhs4_ind_dbl <- as.numeric(dhs_nomiss$ex_htn_nfhs4_ind)

dhs_nomiss_noNAinpsu <- filter(dhs_nomiss, is.na(psu)==F)


####Hyp prev overall

svy_diab <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_nfhs4_ind_dbl))

prevtot <- svy_diab %>%
  summarise(diab_prop = survey_mean(ex_htn_nfhs4_ind_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(diab_ = 100*diab_prop,
         diab_low = 100*diab_prop_low,
         diab_upp = 100*diab_prop_upp)


write_csv(prevtot, "prevhtnoverall NFHS4definition.csv")

```




```{r prevalence hypertension by 5yr age group}

####Hyp prev overall per  5 year age group

svy_diab <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind_dbl,  age_grpOR))

prevtot <- svy_diab %>%
  group_by( age_grpOR) %>% 
  summarize(diab_prop = survey_mean(ex_htn_broad_ind_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(diab_ = 100*diab_prop,
         diab_low = 100*diab_prop_low,
         diab_upp = 100*diab_prop_upp)


write_csv(prevtot, "prevhtnoverall by 5 year age group_2018-03-08.csv")



```

```{r prevalence hypertension by sex and 5yr age group}

####Hyp prev overall per sex and 5 year age group

svy_diab <- dhs_nomiss_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(ex_htn_broad_ind_dbl, female_lab, age_grpOR))

prevtot <- svy_diab %>%
  group_by(female_lab, age_grpOR) %>% 
  summarize(diab_prop = survey_mean(ex_htn_broad_ind_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(diab_ = 100*diab_prop,
         diab_low = 100*diab_prop_low,
         diab_upp = 100*diab_prop_upp)


write_csv(prevtot, "prevhtnoverall by sex and 5 year age group_2018-03-08.csv")

```


```{r prevalence cascade by 5yr age group}

#### Crude screened htn prev by 5 year age group


svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, age_grpOR))

prevtot <- svy_screened %>%
  group_by(age_grpOR) %>% 
  summarize(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


write_csv(prevtot, "stateprevscreenedby 5 year age group_2018-03-08.csv")

#### Crude aware htn prev by 5 year age group


svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, age_grpOR))

prevtot <- svy_aware %>%
  group_by(age_grpOR) %>% 
  summarize(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


write_csv(prevtot, "stateprevawareby 5 year age group_2018-03-08.csv")

#### Crude treated htn prev by 5 year age group


svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, age_grpOR))

prevtot <- svy_treated %>%
  group_by(age_grpOR) %>% 
  summarize(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


write_csv(prevtot, "stateprevtreatedby 5 year age group_2018-03-08.csv")

#### Crude controlled htn prev by 5 year age group


svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, age_grpOR))

prevtot <- svy_controlled %>%
  group_by(age_grpOR) %>% 
  summarize(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)


write_csv(prevtot, "stateprevcontrolledby 5 year age group_2018-03-08.csv")

```

```{r capita figure}

#REG FIG CAPITAL PER STATE#

##screened htn

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_screened = bp_ms & ex_htn_broad_ind==1)
dhs_nomiss[which(is.na(dhs_nomiss$htn_screened)==T), "htn_screened"]<-0

dhs_nomiss$htn_screened <- as.factor(dhs_nomiss$htn_screened)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss$htn_screened)

##aware htn as subset of htn



dhs_nomiss <- mutate(dhs_nomiss,
                     htn_aware = ifelse(hypt==1 | hypt_med==1 & ex_htn_broad_ind==1, 1, 0))


dhs_nomiss$htn_aware <- as.factor(dhs_nomiss$htn_aware)



dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss$htn_aware)

##treated htn as subset of htns


dhs_nomiss <- mutate(dhs_nomiss,
                     htn_treated = ifelse(hypt_med==1 & ex_htn_broad_ind==1, 1, 0))
#dhs_nomiss[which(is.na(dhs_nomiss$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss$htn_treated <- as.factor(dhs_nomiss$htn_treated)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_controlled = ifelse(hypt_med==1 & ex_htn_narrow_ind==0 & ex_htn_broad_ind==1, 1, 0))

dhs_nomiss$htn_controlled <- as.factor(dhs_nomiss$htn_controlled)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss$htn_controlled)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
dhs_nomiss <- mutate(dhs_nomiss, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
dhs_nomiss <- mutate(dhs_nomiss, state_lab = fct_recode(ex_state_ind, 
                                                        "HP" = "Himachal Pradesh",
                                                        "PB" = "Punjab",
                                                        "CH" = "Chandigarh",
                                                        "HR" = "Haryana",
                                                        "DL" = "Delhi",
                                                        "SK" = "Sikkim",
                                                        "DD" = "Daman and Diu",
                                                        "AR" = "Arunachal Pradesh",
                                                        "NL" = "Nagaland",
                                                        "MN" = "Manipur",
                                                        "MZ" = "Mizoram",
                                                        "TR" = "Tripura",
                                                        "ML" = "Meghalaya",
                                                        "WB" = "West Bengal",
                                                        "MH" = "Maharashtra",
                                                        "AP" = "Andhra Pradesh",
                                                        "KA" = "Karnataka",
                                                        "GA" = "Goa",
                                                        "KL" = "Kerala",
                                                        "PY" = "Puducherry",
                                                        "TN" = "Tamil Nadu",
                                                        "AN" = "Andaman and Nicobar Islands",
                                                        "TS" = "Telangana",
                                                        "UK" = "Uttarakhand",
                                                        "RJ" = "Rajasthan",
                                                        "UP" = "Uttar Pradesh",
                                                        "BR" = "Bihar",
                                                        "AS" = "Assam",
                                                        "JK" = "Jammu and Kashmir",
                                                        "GJ" = "Gujarat",
                                                        "JH" = "Jharkhand",
                                                        "OD" = "Odisha",
                                                        "CT" = "Chhattisgarh", 
                                                        "MP" = "Madhya Pradesh"))



dhs_nomiss <- mutate(dhs_nomiss, 
                     urban_dbl = as.numeric(urban))

#install.packages("spatstat")

dhs_nomiss_reg <- dplyr::filter(dhs_nomiss, ex_state_ind != "Puducherry") 
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Daman and Diu")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Delhi")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Dadra and Nagar Haveli")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Andaman and Nicobar Islands")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Lakshadweep")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Chandigarh")




#####Screened 
stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=PCI, x=screenedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=PCI, x=screenedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=PCI, x=screenedmean, label = state_lab)) +
  #geom_label_repel (aes(y=PCI, x=screenedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Screened, in %",
       y = "GDP per capita (int. $)",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0,5000, 10000,15000, 20000,25000), limits=c(0, 25000)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/25000, expand=F)
stateawarefig


#####Aware

stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=PCI, x=awaremean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=PCI, x=awaremean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=PCI, x=awaremean, label = state_lab)) +
  #geom_label_repel (aes(y=PCI, x=awaremean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Aware, in %",
       y = "GDP per capita (int. $)",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0,5000, 10000,15000, 20000,25000), limits=c(0, 25000)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/25000, expand=F)
stateawarefig


#######Treated


stateTreatedfig <- statemean.dat %>% 
  
  ggplot(aes(y=PCI, x=treatedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=PCI, x=treatedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=PCI, x=treatedmean, label = state_lab)) +
  #geom_label_repel (aes(y=PCI, x=treatedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Treated, in %",
       y = "GDP per capita (int. $)",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0,5000, 10000,15000, 20000,25000), limits=c(0, 25000)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/25000, expand=F)
stateTreatedfig



#####Controlled


stateControlledfig <- statemean.dat %>% 
  
  ggplot(aes(y=PCI, x=controlledmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=PCI, x=controlledmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=controlledmean, label= state_lab group=as.factor(controlledmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=PCI, x=controlledmean, label = state_lab)) +
  #geom_label_repel (aes(y=PCI, x=controlledmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Controlled, in %",
       y = "GDP per capita (int. $)",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0,5000, 10000,15000, 20000,25000), limits=c(0, 25000)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/25000, expand=F)
stateControlledfig


```

```{r capital figure with error ribbon}
#REG FIG CAPITAL PER STATE WITH ERRORBARS #

##screened htn

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_screened = bp_ms & ex_htn_broad_ind==1)
dhs_nomiss[which(is.na(dhs_nomiss$htn_screened)==T), "htn_screened"]<-0

dhs_nomiss$htn_screened <- as.factor(dhs_nomiss$htn_screened)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss$htn_screened)

##aware htn as subset of htn



dhs_nomiss <- mutate(dhs_nomiss,
                     htn_aware = ifelse(hypt==1 | hypt_med==1 & ex_htn_broad_ind==1, 1, 0))


dhs_nomiss$htn_aware <- as.factor(dhs_nomiss$htn_aware)



dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss$htn_aware)

##treated htn as subset of htns


dhs_nomiss <- mutate(dhs_nomiss,
                     htn_treated = ifelse(hypt_med==1 & ex_htn_broad_ind==1, 1, 0))
#dhs_nomiss[which(is.na(dhs_nomiss$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss$htn_treated <- as.factor(dhs_nomiss$htn_treated)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_controlled = ifelse(hypt_med==1 & ex_htn_narrow_ind==0 & ex_htn_broad_ind==1, 1, 0))

dhs_nomiss$htn_controlled <- as.factor(dhs_nomiss$htn_controlled)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss$htn_controlled)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
dhs_nomiss <- mutate(dhs_nomiss, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
dhs_nomiss <- mutate(dhs_nomiss, state_lab = fct_recode(ex_state_ind, 
                                                        "HP" = "Himachal Pradesh",
                                                        "PB" = "Punjab",
                                                        "CH" = "Chandigarh",
                                                        "HR" = "Haryana",
                                                        "DL" = "Delhi",
                                                        "SK" = "Sikkim",
                                                        "DD" = "Daman and Diu",
                                                        "AR" = "Arunachal Pradesh",
                                                        "NL" = "Nagaland",
                                                        "MN" = "Manipur",
                                                        "MZ" = "Mizoram",
                                                        "TR" = "Tripura",
                                                        "ML" = "Meghalaya",
                                                        "WB" = "West Bengal",
                                                        "MH" = "Maharashtra",
                                                        "AP" = "Andhra Pradesh",
                                                        "KA" = "Karnataka",
                                                        "GA" = "Goa",
                                                        "KL" = "Kerala",
                                                        "PY" = "Puducherry",
                                                        "TN" = "Tamil Nadu",
                                                        "AN" = "Andaman and Nicobar Islands",
                                                        "TS" = "Telangana",
                                                        "UK" = "Uttarakhand",
                                                        "RJ" = "Rajasthan",
                                                        "UP" = "Uttar Pradesh",
                                                        "BR" = "Bihar",
                                                        "AS" = "Assam",
                                                        "JK" = "Jammu and Kashmir",
                                                        "GJ" = "Gujarat",
                                                        "JH" = "Jharkhand",
                                                        "OD" = "Odisha",
                                                        "CT" = "Chhattisgarh", 
                                                        "MP" = "Madhya Pradesh"))



dhs_nomiss <- mutate(dhs_nomiss, 
                     urban_dbl = as.numeric(urban))

#install.packages("spatstat")

dhs_nomiss_reg <- dplyr::filter(dhs_nomiss, ex_state_ind != "Puducherry") 
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Daman and Diu")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Delhi")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Dadra and Nagar Haveli")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Andaman and Nicobar Islands")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Lakshadweep")
dhs_nomiss_reg <- dplyr::filter(dhs_nomiss_reg, ex_state_ind != "Chandigarh")



#CAPITAL FIGURE WITH ERRORBARS#

###check p-value

summary(lm(formula = state_PCI ~ htn_screened, data = prevtotscreened))
summary(lm(formula = state_PCI ~ htn_aware, data = prevtotaware))
summary(lm(formula = state_PCI ~ htn_treated, data = prevtottreated))
summary(lm(formula = state_PCI ~ htn_controlled, data = prevtotcontrolled))



svy_screened <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_screened_dbl, ex_state_ind))

prevtotscreened <- svy_screened %>%
  group_by(ex_state_ind) %>% 
  summarise(htn_screened_prop = survey_mean(htn_screened_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_screened = 100*htn_screened_prop,
         htn_low = 100*htn_screened_prop_low,
         htn_upp = 100*htn_screened_prop_upp)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
prevtotscreened <- mutate(prevtotscreened, 
                                        # Nothern
                                        zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                                                # Northeastern
                                                                ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                                       # Central
                                                                       ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                                              # Eastern
                                                                              ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                                     # Western
                                                                                     ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                                            # Southern
                                                                                            ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
prevtotscreened <- mutate(prevtotscreened, state_lab = fct_recode(ex_state_ind, 
                                                                                              "HP" = "Himachal Pradesh",
                                                                                              "PB" = "Punjab",
                                                                                              "CH" = "Chandigarh",
                                                                                              "HR" = "Haryana",
                                                                                              "DL" = "Delhi",
                                                                                              "SK" = "Sikkim",
                                                                                              "DD" = "Daman and Diu",
                                                                                              "AR" = "Arunachal Pradesh",
                                                                                              "NL" = "Nagaland",
                                                                                              "MN" = "Manipur",
                                                                                              "MZ" = "Mizoram",
                                                                                              "TR" = "Tripura",
                                                                                              "ML" = "Meghalaya",
                                                                                              "WB" = "West Bengal",
                                                                                              "MH" = "Maharashtra",
                                                                                              "AP" = "Andhra Pradesh",
                                                                                              "KA" = "Karnataka",
                                                                                              "GA" = "Goa",
                                                                                              "KL" = "Kerala",
                                                                                              "PY" = "Puducherry",
                                                                                              "TN" = "Tamil Nadu",
                                                                                              "AN" = "Andaman and Nicobar Islands",
                                                                                              "TS" = "Telangana",
                                                                                              "UK" = "Uttarakhand",
                                                                                              "RJ" = "Rajasthan",
                                                                                              "UP" = "Uttar Pradesh",
                                                                                              "BR" = "Bihar",
                                                                                              "AS" = "Assam",
                                                                                              "JK" = "Jammu and Kashmir",
                                                                                              "GJ" = "Gujarat",
                                                                                              "JH" = "Jharkhand",
                                                                                              "OD" = "Odisha",
                                                                                              "CT" = "Chhattisgarh", 
                                                                                              "MP" = "Madhya Pradesh"))




#install.packages("spatstat")


prevtotscreened <- mutate(prevtotscreened,
                                        state_PCI = ifelse(ex_state_ind== "Andaman and Nicobar Islands",161595.035*(1/16.734), 
                                                           ifelse(ex_state_ind== "Andhra Pradesh",93989.48897*(1/16.734),
                                                                  ifelse(ex_state_ind== "Arunachal Pradesh",97887.8059*(1/16.734),
                                                                         ifelse(ex_state_ind== "Assam",51099.8419*(1/16.734),
                                                                                ifelse(ex_state_ind== "Bihar",33012.94996*(1/16.734),
                                                                                       ifelse(ex_state_ind== "Chandigarh",275484.3905*(1/16.734),
                                                                                              ifelse(ex_state_ind== "Chhattisgarh",72687.6339*(1/16.734),
                                                                                                     ifelse(ex_state_ind== "Delhi",232979.7323*(1/16.734),
                                                                                                            ifelse(ex_state_ind== "Goa",335245.0559*(1/16.734),
                                                                                                                   ifelse(ex_state_ind== "Gujarat",126678.0115*(1/16.734),
                                                                                                                          ifelse(ex_state_ind== "Haryana",153410.0874*(1/16.734),
                                                                                                                                 ifelse(ex_state_ind== "Himachal Pradesh",120305.5909*(1/16.734),
                                                                                                                                        ifelse(ex_state_ind== "Jammu and Kashmir",69825.28608*(1/16.734),
                                                                                                                                               ifelse(ex_state_ind== "Jharkhand",52374.28707*(1/16.734),
                                                                                                                                                      ifelse(ex_state_ind== "Karnataka",100598.087*(1/16.734),
                                                                                                                                                             ifelse(ex_state_ind== "Kerala",118625.7787*(1/16.734),
                                                                                                                                                                    ifelse(ex_state_ind== "Madhya Pradesh",59858.0615*(1/16.734),
                                                                                                                                                                           ifelse(ex_state_ind== "Maharashtra",134384.0679*(1/16.734),
                                                                                                                                                                                  ifelse(ex_state_ind== "Manipur",50157.67944*(1/16.734),
                                                                                                                                                                                         ifelse(ex_state_ind== "Meghalaya",73888.84451*(1/16.734),
                                                                                                                                                                                                ifelse(ex_state_ind== "Mizoram",93847.46347*(1/16.734),
                                                                                                                                                                                                       ifelse(ex_state_ind== "Nagaland",89709.28511*(1/16.734),
                                                                                                                                                                                                              ifelse(ex_state_ind== "Odisha",65035.16039*(1/16.734),
                                                                                                                                                                                                                     ifelse(ex_state_ind== "Puducherry",168892.5785*(1/16.734),
                                                                                                                                                                                                                            ifelse(ex_state_ind== "Punjab",114462.0737*(1/16.734),
                                                                                                                                                                                                                                   ifelse(ex_state_ind== "Rajasthan",75510.83915*(1/16.734),
                                                                                                                                                                                                                                          ifelse(ex_state_ind== "Sikkim",202709.8957*(1/16.734),
                                                                                                                                                                                                                                                 ifelse(ex_state_ind== "Tamil Nadu",118402.3791*(1/16.734),
                                                                                                                                                                                                                                                        ifelse(ex_state_ind== "Tripura",72973.88591*(1/16.734),
                                                                                                                                                                                                                                                               ifelse(ex_state_ind== "Uttar Pradesh",43177.81353*(1/16.734),
                                                                                                                                                                                                                                                                      ifelse(ex_state_ind== "Uttarakhand",121845.5702*(1/16.734),
                                                                                                                                                                                                                                                                             ifelse(ex_state_ind== "West Bengal",77409.18859*(1/16.734),
                                                                                                                                                                                                                                                                                    ifelse(ex_state_ind== "Telangana",111311.9409*(1/16.734),NA))))))))))))))))))))))))))))))))))







prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Puducherry") 
prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Daman and Diu")
prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Delhi")
prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Dadra and Nagar Haveli")
prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Andaman and Nicobar Islands")
prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Lakshadweep")
prevtotscreened <- dplyr::filter(prevtotscreened, ex_state_ind != "Chandigarh")



#####Screened 

screenedbygdp <- prevtotscreened %>% 
  ggplot() +
  geom_smooth(aes(y=htn_screened, x=state_PCI), color="grey50", fill="grey80", alpha=0.7, 
              se=T, method="lm", size=0.7, fullrange=T) +
  geom_point(aes(y= htn_screened, x=state_PCI, color=as.factor(zone)), size=3) +
  geom_text_repel(mapping=aes(y=htn_screened, x=state_PCI, 
                              label = state_lab, fontface=2), 
                  size = 5, segment.color = "black", segment.size = 0.3, family="Times") +
  geom_errorbar(aes(ymin=htn_low, ymax=htn_upp, x=state_PCI, color=as.factor(zone)), 
                width=0.05, alpha=0.5, show.legend = F) +
  theme_classic() + 
  labs(x = "GDP per capita (int. $)",
       y = "Percent",
       fill="") + 
  theme(axis.text.y=element_text(size=20),
        axis.text.x=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=15, family="Times"),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines"),
        title = element_text(size=24, face="bold", family="Times")) + 
  scale_color_brewer(palette="Set1") +
  scale_y_continuous(breaks = seq(from=0, to=100, by=20), limits=c(0, 140)) +
  scale_x_continuous(breaks = seq(from=0, to=25000, by=5000), limits=c(0, 25000)) +
  coord_fixed(25000/100, expand=F)
screenedbygdp 




#####Aware



svy_aware <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_aware_dbl, ex_state_ind))

prevtotaware <- svy_aware %>%
  group_by(ex_state_ind) %>% 
  summarise(htn_aware_prop = survey_mean(htn_aware_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_aware = 100*htn_aware_prop,
         htn_low = 100*htn_aware_prop_low,
         htn_upp = 100*htn_aware_prop_upp)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
prevtotaware <- mutate(prevtotaware, 
                  # Nothern
                  zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                          # Northeastern
                                          ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                 # Central
                                                 ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                        # Eastern
                                                        ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                               # Western
                                                               ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                      # Southern
                                                                      ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
prevtotaware <- mutate(prevtotaware, state_lab = fct_recode(ex_state_ind, 
                                                  "HP" = "Himachal Pradesh",
                                                  "PB" = "Punjab",
                                                  "CH" = "Chandigarh",
                                                  "HR" = "Haryana",
                                                  "DL" = "Delhi",
                                                  "SK" = "Sikkim",
                                                  "DD" = "Daman and Diu",
                                                  "AR" = "Arunachal Pradesh",
                                                  "NL" = "Nagaland",
                                                  "MN" = "Manipur",
                                                  "MZ" = "Mizoram",
                                                  "TR" = "Tripura",
                                                  "ML" = "Meghalaya",
                                                  "WB" = "West Bengal",
                                                  "MH" = "Maharashtra",
                                                  "AP" = "Andhra Pradesh",
                                                  "KA" = "Karnataka",
                                                  "GA" = "Goa",
                                                  "KL" = "Kerala",
                                                  "PY" = "Puducherry",
                                                  "TN" = "Tamil Nadu",
                                                  "AN" = "Andaman and Nicobar Islands",
                                                  "TS" = "Telangana",
                                                  "UK" = "Uttarakhand",
                                                  "RJ" = "Rajasthan",
                                                  "UP" = "Uttar Pradesh",
                                                  "BR" = "Bihar",
                                                  "AS" = "Assam",
                                                  "JK" = "Jammu and Kashmir",
                                                  "GJ" = "Gujarat",
                                                  "JH" = "Jharkhand",
                                                  "OD" = "Odisha",
                                                  "CT" = "Chhattisgarh", 
                                                  "MP" = "Madhya Pradesh"))



prevtotaware <- mutate(prevtotaware, 
                  urban_dbl = as.numeric(urban))

#install.packages("spatstat")


prevtotaware <- mutate(prevtotaware,
                  state_PCI = ifelse(ex_state_ind== "Andaman and Nicobar Islands",161595.035*(1/16.734), 
                                     ifelse(ex_state_ind== "Andhra Pradesh",93989.48897*(1/16.734),
                                            ifelse(ex_state_ind== "Arunachal Pradesh",97887.8059*(1/16.734),
                                                   ifelse(ex_state_ind== "Assam",51099.8419*(1/16.734),
                                                          ifelse(ex_state_ind== "Bihar",33012.94996*(1/16.734),
                                                                 ifelse(ex_state_ind== "Chandigarh",275484.3905*(1/16.734),
                                                                        ifelse(ex_state_ind== "Chhattisgarh",72687.6339*(1/16.734),
                                                                               ifelse(ex_state_ind== "Delhi",232979.7323*(1/16.734),
                                                                                      ifelse(ex_state_ind== "Goa",335245.0559*(1/16.734),
                                                                                             ifelse(ex_state_ind== "Gujarat",126678.0115*(1/16.734),
                                                                                                    ifelse(ex_state_ind== "Haryana",153410.0874*(1/16.734),
                                                                                                           ifelse(ex_state_ind== "Himachal Pradesh",120305.5909*(1/16.734),
                                                                                                                  ifelse(ex_state_ind== "Jammu and Kashmir",69825.28608*(1/16.734),
                                                                                                                         ifelse(ex_state_ind== "Jharkhand",52374.28707*(1/16.734),
                                                                                                                                ifelse(ex_state_ind== "Karnataka",100598.087*(1/16.734),
                                                                                                                                       ifelse(ex_state_ind== "Kerala",118625.7787*(1/16.734),
                                                                                                                                              ifelse(ex_state_ind== "Madhya Pradesh",59858.0615*(1/16.734),
                                                                                                                                                     ifelse(ex_state_ind== "Maharashtra",134384.0679*(1/16.734),
                                                                                                                                                            ifelse(ex_state_ind== "Manipur",50157.67944*(1/16.734),
                                                                                                                                                                   ifelse(ex_state_ind== "Meghalaya",73888.84451*(1/16.734),
                                                                                                                                                                          ifelse(ex_state_ind== "Mizoram",93847.46347*(1/16.734),
                                                                                                                                                                                 ifelse(ex_state_ind== "Nagaland",89709.28511*(1/16.734),
                                                                                                                                                                                        ifelse(ex_state_ind== "Odisha",65035.16039*(1/16.734),
                                                                                                                                                                                               ifelse(ex_state_ind== "Puducherry",168892.5785*(1/16.734),
                                                                                                                                                                                                      ifelse(ex_state_ind== "Punjab",114462.0737*(1/16.734),
                                                                                                                                                                                                             ifelse(ex_state_ind== "Rajasthan",75510.83915*(1/16.734),
                                                                                                                                                                                                                    ifelse(ex_state_ind== "Sikkim",202709.8957*(1/16.734),
                                                                                                                                                                                                                           ifelse(ex_state_ind== "Tamil Nadu",118402.3791*(1/16.734),
                                                                                                                                                                                                                                  ifelse(ex_state_ind== "Tripura",72973.88591*(1/16.734),
                                                                                                                                                                                                                                         ifelse(ex_state_ind== "Uttar Pradesh",43177.81353*(1/16.734),
                                                                                                                                                                                                                                                ifelse(ex_state_ind== "Uttarakhand",121845.5702*(1/16.734),
                                                                                                                                                                                                                                                       ifelse(ex_state_ind== "West Bengal",77409.18859*(1/16.734),
                                                                                                                                                                                                                                                              ifelse(ex_state_ind== "Telangana",111311.9409*(1/16.734),NA))))))))))))))))))))))))))))))))))







prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Puducherry") 
prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Daman and Diu")
prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Delhi")
prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Dadra and Nagar Haveli")
prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Andaman and Nicobar Islands")
prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Lakshadweep")
prevtotaware <- dplyr::filter(prevtotaware, ex_state_ind != "Chandigarh")



#####aware 

awarebygdp <- prevtotaware %>% 
  ggplot() +
  geom_smooth(aes(y=htn_aware, x=state_PCI), color="grey50", fill="grey80", alpha=0.7, 
              se=T, method="lm", size=0.7, fullrange=T) +
  geom_point(aes(y= htn_aware, x=state_PCI, color=as.factor(zone)), size=3) +
  geom_text_repel(mapping=aes(y=htn_aware, x=state_PCI, 
                              label = state_lab, fontface=2), 
                  size = 5, segment.color = "black", segment.size = 0.3, family="Times") +
  geom_errorbar(aes(ymin=htn_low, ymax=htn_upp, x=state_PCI, color=as.factor(zone)), 
                width=0.05, alpha=0.5, show.legend = F) +
  theme_classic() + 
  labs(x = "GDP per capita (int. $)",
       y = "Percent",
       fill="") + 
  theme(axis.text.y=element_text(size=20),
        axis.text.x=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=15, family="Times"),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines"),
        title = element_text(size=24, face="bold", family="Times")) + 
  scale_color_brewer(palette="Set1") +
  scale_y_continuous(breaks = seq(from=0, to=100, by=20), limits=c(0, 140)) +
  scale_x_continuous(breaks = seq(from=0, to=25000, by=5000), limits=c(0, 25000)) +
  coord_fixed(25000/100, expand=F)
awarebygdp 

#####treated



svy_treated <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_treated_dbl, ex_state_ind))

prevtottreated <- svy_treated %>%
  group_by(ex_state_ind) %>% 
  summarise(htn_treated_prop = survey_mean(htn_treated_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_treated = 100*htn_treated_prop,
         htn_low = 100*htn_treated_prop_low,
         htn_upp = 100*htn_treated_prop_upp)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
prevtottreated <- mutate(prevtottreated, 
                       # Nothern
                       zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                               # Northeastern
                                               ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                      # Central
                                                      ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                             # Eastern
                                                             ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                    # Western
                                                                    ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                           # Southern
                                                                           ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
prevtottreated <- mutate(prevtottreated, state_lab = fct_recode(ex_state_ind, 
                                                            "HP" = "Himachal Pradesh",
                                                            "PB" = "Punjab",
                                                            "CH" = "Chandigarh",
                                                            "HR" = "Haryana",
                                                            "DL" = "Delhi",
                                                            "SK" = "Sikkim",
                                                            "DD" = "Daman and Diu",
                                                            "AR" = "Arunachal Pradesh",
                                                            "NL" = "Nagaland",
                                                            "MN" = "Manipur",
                                                            "MZ" = "Mizoram",
                                                            "TR" = "Tripura",
                                                            "ML" = "Meghalaya",
                                                            "WB" = "West Bengal",
                                                            "MH" = "Maharashtra",
                                                            "AP" = "Andhra Pradesh",
                                                            "KA" = "Karnataka",
                                                            "GA" = "Goa",
                                                            "KL" = "Kerala",
                                                            "PY" = "Puducherry",
                                                            "TN" = "Tamil Nadu",
                                                            "AN" = "Andaman and Nicobar Islands",
                                                            "TS" = "Telangana",
                                                            "UK" = "Uttarakhand",
                                                            "RJ" = "Rajasthan",
                                                            "UP" = "Uttar Pradesh",
                                                            "BR" = "Bihar",
                                                            "AS" = "Assam",
                                                            "JK" = "Jammu and Kashmir",
                                                            "GJ" = "Gujarat",
                                                            "JH" = "Jharkhand",
                                                            "OD" = "Odisha",
                                                            "CT" = "Chhattisgarh", 
                                                            "MP" = "Madhya Pradesh"))



prevtottreated <- mutate(prevtottreated, 
                       urban_dbl = as.numeric(urban))

#install.packages("spatstat")


prevtottreated <- mutate(prevtottreated,
                       state_PCI = ifelse(ex_state_ind== "Andaman and Nicobar Islands",161595.035*(1/16.734), 
                                          ifelse(ex_state_ind== "Andhra Pradesh",93989.48897*(1/16.734),
                                                 ifelse(ex_state_ind== "Arunachal Pradesh",97887.8059*(1/16.734),
                                                        ifelse(ex_state_ind== "Assam",51099.8419*(1/16.734),
                                                               ifelse(ex_state_ind== "Bihar",33012.94996*(1/16.734),
                                                                      ifelse(ex_state_ind== "Chandigarh",275484.3905*(1/16.734),
                                                                             ifelse(ex_state_ind== "Chhattisgarh",72687.6339*(1/16.734),
                                                                                    ifelse(ex_state_ind== "Delhi",232979.7323*(1/16.734),
                                                                                           ifelse(ex_state_ind== "Goa",335245.0559*(1/16.734),
                                                                                                  ifelse(ex_state_ind== "Gujarat",126678.0115*(1/16.734),
                                                                                                         ifelse(ex_state_ind== "Haryana",153410.0874*(1/16.734),
                                                                                                                ifelse(ex_state_ind== "Himachal Pradesh",120305.5909*(1/16.734),
                                                                                                                       ifelse(ex_state_ind== "Jammu and Kashmir",69825.28608*(1/16.734),
                                                                                                                              ifelse(ex_state_ind== "Jharkhand",52374.28707*(1/16.734),
                                                                                                                                     ifelse(ex_state_ind== "Karnataka",100598.087*(1/16.734),
                                                                                                                                            ifelse(ex_state_ind== "Kerala",118625.7787*(1/16.734),
                                                                                                                                                   ifelse(ex_state_ind== "Madhya Pradesh",59858.0615*(1/16.734),
                                                                                                                                                          ifelse(ex_state_ind== "Maharashtra",134384.0679*(1/16.734),
                                                                                                                                                                 ifelse(ex_state_ind== "Manipur",50157.67944*(1/16.734),
                                                                                                                                                                        ifelse(ex_state_ind== "Meghalaya",73888.84451*(1/16.734),
                                                                                                                                                                               ifelse(ex_state_ind== "Mizoram",93847.46347*(1/16.734),
                                                                                                                                                                                      ifelse(ex_state_ind== "Nagaland",89709.28511*(1/16.734),
                                                                                                                                                                                             ifelse(ex_state_ind== "Odisha",65035.16039*(1/16.734),
                                                                                                                                                                                                    ifelse(ex_state_ind== "Puducherry",168892.5785*(1/16.734),
                                                                                                                                                                                                           ifelse(ex_state_ind== "Punjab",114462.0737*(1/16.734),
                                                                                                                                                                                                                  ifelse(ex_state_ind== "Rajasthan",75510.83915*(1/16.734),
                                                                                                                                                                                                                         ifelse(ex_state_ind== "Sikkim",202709.8957*(1/16.734),
                                                                                                                                                                                                                                ifelse(ex_state_ind== "Tamil Nadu",118402.3791*(1/16.734),
                                                                                                                                                                                                                                       ifelse(ex_state_ind== "Tripura",72973.88591*(1/16.734),
                                                                                                                                                                                                                                              ifelse(ex_state_ind== "Uttar Pradesh",43177.81353*(1/16.734),
                                                                                                                                                                                                                                                     ifelse(ex_state_ind== "Uttarakhand",121845.5702*(1/16.734),
                                                                                                                                                                                                                                                            ifelse(ex_state_ind== "West Bengal",77409.18859*(1/16.734),
                                                                                                                                                                                                                                                                   ifelse(ex_state_ind== "Telangana",111311.9409*(1/16.734),NA))))))))))))))))))))))))))))))))))







prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Puducherry") 
prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Daman and Diu")
prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Delhi")
prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Dadra and Nagar Haveli")
prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Andaman and Nicobar Islands")
prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Lakshadweep")
prevtottreated <- dplyr::filter(prevtottreated, ex_state_ind != "Chandigarh")



#####treated 

treatedbygdp <- prevtottreated %>% 
  ggplot() +
  geom_smooth(aes(y=htn_treated, x=state_PCI), color="grey50", fill="grey80", alpha=0.7, 
              se=T, method="lm", size=0.7, fullrange=T) +
  geom_point(aes(y= htn_treated, x=state_PCI, color=as.factor(zone)), size=3) +
  geom_text_repel(mapping=aes(y=htn_treated, x=state_PCI, 
                              label = state_lab, fontface=2), 
                  size = 5, segment.color = "black", segment.size = 0.3, family="Times") +
  geom_errorbar(aes(ymin=htn_low, ymax=htn_upp, x=state_PCI, color=as.factor(zone)), 
                width=0.05, alpha=0.5, show.legend = F) +
  theme_classic() + 
  labs(x = "GDP per capita (int. $)",
       y = "Percent",
       fill="") + 
  theme(axis.text.y=element_text(size=20),
        axis.text.x=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=15, family="Times"),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines"),
        title = element_text(size=24, face="bold", family="Times")) + 
  scale_color_brewer(palette="Set1") +
  scale_y_continuous(breaks = seq(from=0, to=100, by=20), limits=c(0, 140)) +
  scale_x_continuous(breaks = seq(from=0, to=25000, by=5000), limits=c(0, 25000)) +
  coord_fixed(25000/100, expand=F)
treatedbygdp 



#####controlled



svy_controlled <- dhs_nomiss_htn_only_noNAinpsu %>% 
  as_survey_design(stratum = stratum,
                   ids = c(psuid, hh_id),
                   weights = p_wt_new,
                   variables = c(htn_controlled_dbl, ex_state_ind))

prevtotcontrolled <- svy_controlled %>%
  group_by(ex_state_ind) %>% 
  summarise(htn_controlled_prop = survey_mean(htn_controlled_dbl, proportion=TRUE, vartype = "ci")) %>% 
  mutate(htn_controlled = 100*htn_controlled_prop,
         htn_low = 100*htn_controlled_prop_low,
         htn_upp = 100*htn_controlled_prop_upp)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
prevtotcontrolled <- mutate(prevtotcontrolled, 
                         # Nothern
                         zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                                 # Northeastern
                                                 ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                        # Central
                                                        ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                               # Eastern
                                                               ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                      # Western
                                                                      ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                             # Southern
                                                                             ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
prevtotcontrolled <- mutate(prevtotcontrolled, state_lab = fct_recode(ex_state_ind, 
                                                                "HP" = "Himachal Pradesh",
                                                                "PB" = "Punjab",
                                                                "CH" = "Chandigarh",
                                                                "HR" = "Haryana",
                                                                "DL" = "Delhi",
                                                                "SK" = "Sikkim",
                                                                "DD" = "Daman and Diu",
                                                                "AR" = "Arunachal Pradesh",
                                                                "NL" = "Nagaland",
                                                                "MN" = "Manipur",
                                                                "MZ" = "Mizoram",
                                                                "TR" = "Tripura",
                                                                "ML" = "Meghalaya",
                                                                "WB" = "West Bengal",
                                                                "MH" = "Maharashtra",
                                                                "AP" = "Andhra Pradesh",
                                                                "KA" = "Karnataka",
                                                                "GA" = "Goa",
                                                                "KL" = "Kerala",
                                                                "PY" = "Puducherry",
                                                                "TN" = "Tamil Nadu",
                                                                "AN" = "Andaman and Nicobar Islands",
                                                                "TS" = "Telangana",
                                                                "UK" = "Uttarakhand",
                                                                "RJ" = "Rajasthan",
                                                                "UP" = "Uttar Pradesh",
                                                                "BR" = "Bihar",
                                                                "AS" = "Assam",
                                                                "JK" = "Jammu and Kashmir",
                                                                "GJ" = "Gujarat",
                                                                "JH" = "Jharkhand",
                                                                "OD" = "Odisha",
                                                                "CT" = "Chhattisgarh", 
                                                                "MP" = "Madhya Pradesh"))



prevtotcontrolled <- mutate(prevtotcontrolled, 
                         urban_dbl = as.numeric(urban))

#install.packages("spatstat")


prevtotcontrolled <- mutate(prevtotcontrolled,
                         state_PCI = ifelse(ex_state_ind== "Andaman and Nicobar Islands",161595.035*(1/16.734), 
                                            ifelse(ex_state_ind== "Andhra Pradesh",93989.48897*(1/16.734),
                                                   ifelse(ex_state_ind== "Arunachal Pradesh",97887.8059*(1/16.734),
                                                          ifelse(ex_state_ind== "Assam",51099.8419*(1/16.734),
                                                                 ifelse(ex_state_ind== "Bihar",33012.94996*(1/16.734),
                                                                        ifelse(ex_state_ind== "Chandigarh",275484.3905*(1/16.734),
                                                                               ifelse(ex_state_ind== "Chhattisgarh",72687.6339*(1/16.734),
                                                                                      ifelse(ex_state_ind== "Delhi",232979.7323*(1/16.734),
                                                                                             ifelse(ex_state_ind== "Goa",335245.0559*(1/16.734),
                                                                                                    ifelse(ex_state_ind== "Gujarat",126678.0115*(1/16.734),
                                                                                                           ifelse(ex_state_ind== "Haryana",153410.0874*(1/16.734),
                                                                                                                  ifelse(ex_state_ind== "Himachal Pradesh",120305.5909*(1/16.734),
                                                                                                                         ifelse(ex_state_ind== "Jammu and Kashmir",69825.28608*(1/16.734),
                                                                                                                                ifelse(ex_state_ind== "Jharkhand",52374.28707*(1/16.734),
                                                                                                                                       ifelse(ex_state_ind== "Karnataka",100598.087*(1/16.734),
                                                                                                                                              ifelse(ex_state_ind== "Kerala",118625.7787*(1/16.734),
                                                                                                                                                     ifelse(ex_state_ind== "Madhya Pradesh",59858.0615*(1/16.734),
                                                                                                                                                            ifelse(ex_state_ind== "Maharashtra",134384.0679*(1/16.734),
                                                                                                                                                                   ifelse(ex_state_ind== "Manipur",50157.67944*(1/16.734),
                                                                                                                                                                          ifelse(ex_state_ind== "Meghalaya",73888.84451*(1/16.734),
                                                                                                                                                                                 ifelse(ex_state_ind== "Mizoram",93847.46347*(1/16.734),
                                                                                                                                                                                        ifelse(ex_state_ind== "Nagaland",89709.28511*(1/16.734),
                                                                                                                                                                                               ifelse(ex_state_ind== "Odisha",65035.16039*(1/16.734),
                                                                                                                                                                                                      ifelse(ex_state_ind== "Puducherry",168892.5785*(1/16.734),
                                                                                                                                                                                                             ifelse(ex_state_ind== "Punjab",114462.0737*(1/16.734),
                                                                                                                                                                                                                    ifelse(ex_state_ind== "Rajasthan",75510.83915*(1/16.734),
                                                                                                                                                                                                                           ifelse(ex_state_ind== "Sikkim",202709.8957*(1/16.734),
                                                                                                                                                                                                                                  ifelse(ex_state_ind== "Tamil Nadu",118402.3791*(1/16.734),
                                                                                                                                                                                                                                         ifelse(ex_state_ind== "Tripura",72973.88591*(1/16.734),
                                                                                                                                                                                                                                                ifelse(ex_state_ind== "Uttar Pradesh",43177.81353*(1/16.734),
                                                                                                                                                                                                                                                       ifelse(ex_state_ind== "Uttarakhand",121845.5702*(1/16.734),
                                                                                                                                                                                                                                                              ifelse(ex_state_ind== "West Bengal",77409.18859*(1/16.734),
                                                                                                                                                                                                                                                                     ifelse(ex_state_ind== "Telangana",111311.9409*(1/16.734),NA))))))))))))))))))))))))))))))))))







prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Puducherry") 
prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Daman and Diu")
prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Delhi")
prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Dadra and Nagar Haveli")
prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Andaman and Nicobar Islands")
prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Lakshadweep")
prevtotcontrolled <- dplyr::filter(prevtotcontrolled, ex_state_ind != "Chandigarh")



#####controlled 

controlledbygdp <- prevtotcontrolled %>% 
  ggplot() +
  geom_smooth(aes(y=htn_controlled, x=state_PCI), color="grey50", fill="grey80", alpha=0.7, 
              se=T, method="lm", size=0.7, fullrange=T) +
  geom_point(aes(y= htn_controlled, x=state_PCI, color=as.factor(zone)), size=3) +
  geom_text_repel(mapping=aes(y=htn_controlled, x=state_PCI, 
                              label = state_lab, fontface=2), 
                  size = 5, segment.color = "black", segment.size = 0.3, family="Times") +
  geom_errorbar(aes(ymin=htn_low, ymax=htn_upp, x=state_PCI, color=as.factor(zone)), 
                width=0.05, alpha=0.5, show.legend = F) +
  theme_classic() + 
  labs(x = "GDP per capita (int. $)",
       y = "Percent",
       fill="") + 
  theme(axis.text.y=element_text(size=20),
        axis.text.x=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=15, family="Times"),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines"),
        title = element_text(size=24, face="bold", family="Times")) + 
  scale_color_brewer(palette="Set1") +
  scale_y_continuous(breaks = seq(from=0, to=100, by=20), limits=c(0, 140)) +
  scale_x_continuous(breaks = seq(from=0, to=25000, by=5000), limits=c(0, 25000)) +
  coord_fixed(25000/100, expand=F)
controlledbygdp 







```


```{r regression figure different hypertension definition}






##############Regression figure low htn prevalence low outcomes

######Create htn care indicators in dhs_nomiss


#####SPECIAL htn DEFINITION

dhs_nomiss <-mutate(dhs_nomiss,
                    ex_htn_broad_ind =  ifelse(hypt_med==1 | ex_htn_narrow_ind==1, 1, 0))
dhs_nomiss[which(is.na(dhs_nomiss$ex_htn_broad_ind)==T), "ex_htn_broad_ind"]<-0

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     ex_htn_broad_ind_dbl = as.numeric(ex_htn_broad_ind))


##screened htn

dhs_nomiss <- mutate(dhs_nomiss,
                              htn_screened = bp_ms & ex_htn_broad_ind==1)
dhs_nomiss[which(is.na(dhs_nomiss$htn_screened)==T), "htn_screened"]<-0

dhs_nomiss$htn_screened <- as.factor(dhs_nomiss$htn_screened)

dhs_nomiss <- mutate(dhs_nomiss,
                              
                              htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss$htn_screened)

##aware htn as subset of htn



dhs_nomiss <- mutate(dhs_nomiss,
                              htn_aware = ifelse(hypt==1 | hypt_med==1 & ex_htn_broad_ind==1, 1, 0))


dhs_nomiss$htn_aware <- as.factor(dhs_nomiss$htn_aware)



dhs_nomiss <- mutate(dhs_nomiss,
                              
                              htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss$htn_aware)

##treated htn as subset of htns


dhs_nomiss <- mutate(dhs_nomiss,
                              htn_treated = ifelse(hypt_med==1 & ex_htn_broad_ind==1, 1, 0))
#dhs_nomiss[which(is.na(dhs_nomiss$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss$htn_treated <- as.factor(dhs_nomiss$htn_treated)

dhs_nomiss <- mutate(dhs_nomiss,
                              
                              htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss <- mutate(dhs_nomiss,
                              htn_controlled = ifelse(hypt_med==1 & ex_htn_narrow_ind==0 & ex_htn_broad_ind==1, 1, 0))

dhs_nomiss$htn_controlled <- as.factor(dhs_nomiss$htn_controlled)

dhs_nomiss <- mutate(dhs_nomiss,
                              
                              htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss$htn_controlled)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
dhs_nomiss <- mutate(dhs_nomiss, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
dhs_nomiss <- mutate(dhs_nomiss, state_lab = fct_recode(ex_state_ind, 
                                                        "HP" = "Himachal Pradesh",
                                                        "PB" = "Punjab",
                                                        "CH" = "Chandigarh",
                                                        "HR" = "Haryana",
                                                        "DL" = "Delhi",
                                                        "SK" = "Sikkim",
                                                        "DD" = "Daman and Diu",
                                                        "AR" = "Arunachal Pradesh",
                                                        "NL" = "Nagaland",
                                                        "MN" = "Manipur",
                                                        "MZ" = "Mizoram",
                                                        "TR" = "Tripura",
                                                        "ML" = "Meghalaya",
                                                        "WB" = "West Bengal",
                                                        "MH" = "Maharashtra",
                                                        "AP" = "Andhra Pradesh",
                                                        "KA" = "Karnataka",
                                                        "GA" = "Goa",
                                                        "KL" = "Kerala",
                                                        "PY" = "Puducherry",
                                                        "TN" = "Tamil Nadu",
                                                        "AN" = "Andaman and Nicobar Islands",
                                                        "TS" = "Telangana",
                                                        "UK" = "Uttarakhand",
                                                        "RJ" = "Rajasthan",
                                                        "UP" = "Uttar Pradesh",
                                                        "BR" = "Bihar",
                                                        "AS" = "Assam",
                                                        "JK" = "Jammu and Kashmir",
                                                        "GJ" = "Gujarat",
                                                        "JH" = "Jharkhand",
                                                        "OD" = "Odisha",
                                                        "CT" = "Chhattisgarh", 
                                                        "MP" = "Madhya Pradesh"))



dhs_nomiss <- mutate(dhs_nomiss, 
                     urban_dbl = as.numeric(urban))

#install.packages("spatstat")

dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Puducherry") 
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Daman and Diu")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Delhi")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Dadra and Nagar Haveli")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Andaman and Nicobar Islands")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Lakshadweep")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Chandigarh")

library(spatstat)
statemean.dat <- dhs_nomiss %>%
  group_by(ex_state_ind) %>% 
  mutate(prop_urban = weighted.mean(urban_dbl, p_wt_new, na.rm=TRUE)) %>% 
  mutate(htn = weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)*100,
         screenedmean = ((weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         awaremean = ((weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         treatedmean = ((weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100,
         controlledmean = ((weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100) %>%
  filter(row_number()==1) %>%
  ungroup() %>% 
  dplyr::select(ex_state_ind, state_lab, zone, htn, screenedmean, awaremean, treatedmean, controlledmean,  prop_urban)

write.csv(statemean.dat, "Colored reg fig estimates htn.csv")

#####Screened 
stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=screenedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=screenedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=screenedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=screenedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Screened, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateawarefig


#####Aware

stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=awaremean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=awaremean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=awaremean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=awaremean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Aware, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateawarefig


#######Treated


stateTreatedfig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=treatedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=treatedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=treatedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=treatedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Treated, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateTreatedfig



#####Controlled


stateControlledfig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=controlledmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=controlledmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=controlledmean, label= state_lab group=as.factor(controlledmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=controlledmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=controlledmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Controlled, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateControlledfig


summary(lm(formula = htn ~ screenedmean, data = statemean.dat))
summary(lm(formula = htn ~ awaremean, data = statemean.dat))
summary(lm(formula = htn ~ treatedmean, data = statemean.dat))
summary(lm(formula = htn ~ controlledmean, data = statemean.dat))



```

```{r regression figure different hypertension definition only measurement}
#################Only htn_narrow as htn#########



#####SPECIAL htn DEFINITION

dhs_nomiss <-mutate(dhs_nomiss,
                    ex_htn_broad_ind =  ifelse( ex_htn_narrow_ind==1, 1, 0))
dhs_nomiss[which(is.na(dhs_nomiss$ex_htn_broad_ind)==T), "ex_htn_broad_ind"]<-0

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     ex_htn_broad_ind_dbl = as.numeric(ex_htn_broad_ind))


##screened htn

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_screened = bp_ms & ex_htn_broad_ind==1)
dhs_nomiss[which(is.na(dhs_nomiss$htn_screened)==T), "htn_screened"]<-0

dhs_nomiss$htn_screened <- as.factor(dhs_nomiss$htn_screened)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss$htn_screened)

##aware htn as subset of htn



dhs_nomiss <- mutate(dhs_nomiss,
                     htn_aware = ifelse(hypt==1 | hypt_med==1 & ex_htn_broad_ind==1, 1, 0))


dhs_nomiss$htn_aware <- as.factor(dhs_nomiss$htn_aware)



dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss$htn_aware)

##treated htn as subset of htns


dhs_nomiss <- mutate(dhs_nomiss,
                     htn_treated = ifelse(hypt_med==1 & ex_htn_broad_ind==1, 1, 0))
#dhs_nomiss[which(is.na(dhs_nomiss$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss$htn_treated <- as.factor(dhs_nomiss$htn_treated)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_controlled = ifelse(hypt_med==1 & ex_htn_narrow_ind==0 & ex_htn_broad_ind==1, 1, 0))

dhs_nomiss$htn_controlled <- as.factor(dhs_nomiss$htn_controlled)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss$htn_controlled)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
dhs_nomiss <- mutate(dhs_nomiss, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
dhs_nomiss <- mutate(dhs_nomiss, state_lab = fct_recode(ex_state_ind, 
                                                        "HP" = "Himachal Pradesh",
                                                        "PB" = "Punjab",
                                                        "CH" = "Chandigarh",
                                                        "HR" = "Haryana",
                                                        "DL" = "Delhi",
                                                        "SK" = "Sikkim",
                                                        "DD" = "Daman and Diu",
                                                        "AR" = "Arunachal Pradesh",
                                                        "NL" = "Nagaland",
                                                        "MN" = "Manipur",
                                                        "MZ" = "Mizoram",
                                                        "TR" = "Tripura",
                                                        "ML" = "Meghalaya",
                                                        "WB" = "West Bengal",
                                                        "MH" = "Maharashtra",
                                                        "AP" = "Andhra Pradesh",
                                                        "KA" = "Karnataka",
                                                        "GA" = "Goa",
                                                        "KL" = "Kerala",
                                                        "PY" = "Puducherry",
                                                        "TN" = "Tamil Nadu",
                                                        "AN" = "Andaman and Nicobar Islands",
                                                        "TS" = "Telangana",
                                                        "UK" = "Uttarakhand",
                                                        "RJ" = "Rajasthan",
                                                        "UP" = "Uttar Pradesh",
                                                        "BR" = "Bihar",
                                                        "AS" = "Assam",
                                                        "JK" = "Jammu and Kashmir",
                                                        "GJ" = "Gujarat",
                                                        "JH" = "Jharkhand",
                                                        "OD" = "Odisha",
                                                        "CT" = "Chhattisgarh", 
                                                        "MP" = "Madhya Pradesh"))



dhs_nomiss <- mutate(dhs_nomiss, 
                     urban_dbl = as.numeric(urban))

#install.packages("spatstat")

dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Puducherry") 
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Daman and Diu")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Delhi")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Dadra and Nagar Haveli")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Andaman and Nicobar Islands")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Lakshadweep")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Chandigarh")

library(spatstat)
statemean.dat <- dhs_nomiss %>%
  group_by(ex_state_ind) %>% 
  mutate(prop_urban = weighted.mean(urban_dbl, p_wt_new, na.rm=TRUE)) %>% 
  mutate(htn = weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)*100,
         screenedmean = ((weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         awaremean = ((weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         treatedmean = ((weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100,
         controlledmean = ((weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100) %>%
  filter(row_number()==1) %>%
  ungroup() %>% 
  dplyr::select(ex_state_ind, state_lab, zone, htn, screenedmean, awaremean, treatedmean, controlledmean,  prop_urban)

write.csv(statemean.dat, "Colored reg fig estimates htn.csv")

#####Screened 
stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=screenedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=screenedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=screenedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=screenedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Screened, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateawarefig


#####Aware

stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=awaremean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=awaremean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=awaremean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=awaremean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Aware, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateawarefig


#######Treated


stateTreatedfig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=treatedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=treatedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  geom_text_repel(aes(y=htn, x=treatedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=treatedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Treated, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30), limits=c(0, 30)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/30, expand=F)
stateTreatedfig




summary(lm(formula = htn ~ screenedmean, data = statemean.dat))
summary(lm(formula = htn ~ awaremean, data = statemean.dat))
summary(lm(formula = htn ~ treatedmean, data = statemean.dat))




```


```{r regression figure different hypertension definition DISTRICTS }
######################Districts with treated######################################################################################


#####SPECIAL htn DEFINITION

dhs_nomiss <-mutate(dhs_nomiss,
                    ex_htn_broad_ind =  ifelse(hypt_med==1 | ex_htn_narrow_ind==1, 1, 0))
dhs_nomiss[which(is.na(dhs_nomiss$ex_htn_broad_ind)==T), "ex_htn_broad_ind"]<-0

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     ex_htn_broad_ind_dbl = as.numeric(ex_htn_broad_ind))


##screened htn

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_screened = bp_ms & ex_htn_broad_ind==1)
dhs_nomiss[which(is.na(dhs_nomiss$htn_screened)==T), "htn_screened"]<-0

dhs_nomiss$htn_screened <- as.factor(dhs_nomiss$htn_screened)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss$htn_screened)

##aware htn as subset of htn



dhs_nomiss <- mutate(dhs_nomiss,
                     htn_aware = ifelse(hypt==1 | hypt_med==1 & ex_htn_broad_ind==1, 1, 0))


dhs_nomiss$htn_aware <- as.factor(dhs_nomiss$htn_aware)



dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss$htn_aware)

##treated htn as subset of htns


dhs_nomiss <- mutate(dhs_nomiss,
                     htn_treated = ifelse(hypt_med==1 & ex_htn_broad_ind==1, 1, 0))
#dhs_nomiss[which(is.na(dhs_nomiss$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss$htn_treated <- as.factor(dhs_nomiss$htn_treated)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_controlled = ifelse(hypt_med==1 & ex_htn_narrow_ind==0 & ex_htn_broad_ind==1, 1, 0))

dhs_nomiss$htn_controlled <- as.factor(dhs_nomiss$htn_controlled)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss$htn_controlled)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
dhs_nomiss <- mutate(dhs_nomiss, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
dhs_nomiss <- mutate(dhs_nomiss, state_lab = fct_recode(ex_state_ind, 
                                                        "HP" = "Himachal Pradesh",
                                                        "PB" = "Punjab",
                                                        "CH" = "Chandigarh",
                                                        "HR" = "Haryana",
                                                        "DL" = "Delhi",
                                                        "SK" = "Sikkim",
                                                        "DD" = "Daman and Diu",
                                                        "AR" = "Arunachal Pradesh",
                                                        "NL" = "Nagaland",
                                                        "MN" = "Manipur",
                                                        "MZ" = "Mizoram",
                                                        "TR" = "Tripura",
                                                        "ML" = "Meghalaya",
                                                        "WB" = "West Bengal",
                                                        "MH" = "Maharashtra",
                                                        "AP" = "Andhra Pradesh",
                                                        "KA" = "Karnataka",
                                                        "GA" = "Goa",
                                                        "KL" = "Kerala",
                                                        "PY" = "Puducherry",
                                                        "TN" = "Tamil Nadu",
                                                        "AN" = "Andaman and Nicobar Islands",
                                                        "TS" = "Telangana",
                                                        "UK" = "Uttarakhand",
                                                        "RJ" = "Rajasthan",
                                                        "UP" = "Uttar Pradesh",
                                                        "BR" = "Bihar",
                                                        "AS" = "Assam",
                                                        "JK" = "Jammu and Kashmir",
                                                        "GJ" = "Gujarat",
                                                        "JH" = "Jharkhand",
                                                        "OD" = "Odisha",
                                                        "CT" = "Chhattisgarh", 
                                                        "MP" = "Madhya Pradesh"))



dhs_nomiss <- mutate(dhs_nomiss, 
                     urban_dbl = as.numeric(urban))

#install.packages("spatstat")

dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Puducherry") 
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Daman and Diu")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Delhi")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Dadra and Nagar Haveli")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Andaman and Nicobar Islands")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Lakshadweep")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Chandigarh")

library(spatstat)
statemean.dat <- dhs_nomiss %>%
  group_by(d_id) %>% 
  mutate(prop_urban = weighted.mean(urban_dbl, p_wt_new, na.rm=TRUE)) %>% 
  mutate(htn = weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)*100,
         screenedmean = ((weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         awaremean = ((weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         treatedmean = ((weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100,
         controlledmean = ((weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100) %>%
  filter(row_number()==1) %>%
  ungroup() %>% 
  dplyr::select(d_id, zone, htn, screenedmean, awaremean, treatedmean, controlledmean,  prop_urban)

write.csv(statemean.dat, "Colored reg fig estimates htn.csv")

#####Screened 
stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=screenedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=screenedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
 # geom_text_repel(aes(y=htn, x=screenedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=screenedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Screened, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30, 35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateawarefig


#####Aware

stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=awaremean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=awaremean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  #geom_text_repel(aes(y=htn, x=awaremean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=awaremean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Aware, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30,35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateawarefig


#######Treated


stateTreatedfig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=treatedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=treatedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  #geom_text_repel(aes(y=htn, x=treatedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=treatedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Treated, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30, 35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateTreatedfig



#####Controlled


stateControlledfig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=controlledmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=controlledmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=controlledmean, label= state_lab group=as.factor(controlledmean)), outlier.shape = NA, alpha=0.8) +
 # geom_text_repel(aes(y=htn, x=controlledmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=controlledmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Controlled, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateControlledfig




summary(lm(formula = htn ~ screenedmean, data = statemean.dat))
summary(lm(formula = htn ~ awaremean, data = statemean.dat))
summary(lm(formula = htn ~ treatedmean, data = statemean.dat))
summary(lm(formula = htn ~ controlledmean, data = statemean.dat))


```

```{r regression figure different hypertension definition only measurement DISTRICTS}

####################District without treated

#####SPECIAL htn DEFINITION

dhs_nomiss <-mutate(dhs_nomiss,
                    ex_htn_broad_ind =  ifelse( ex_htn_narrow_ind==1, 1, 0))
dhs_nomiss[which(is.na(dhs_nomiss$ex_htn_broad_ind)==T), "ex_htn_broad_ind"]<-0

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     ex_htn_broad_ind_dbl = as.numeric(ex_htn_broad_ind))


##screened htn

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_screened = bp_ms & ex_htn_broad_ind==1)
dhs_nomiss[which(is.na(dhs_nomiss$htn_screened)==T), "htn_screened"]<-0

dhs_nomiss$htn_screened <- as.factor(dhs_nomiss$htn_screened)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_screened_dbl = as.numeric(htn_screened)-1)

summary(dhs_nomiss$htn_screened)

##aware htn as subset of htn



dhs_nomiss <- mutate(dhs_nomiss,
                     htn_aware = ifelse(hypt==1 | hypt_med==1 & ex_htn_broad_ind==1, 1, 0))


dhs_nomiss$htn_aware <- as.factor(dhs_nomiss$htn_aware)



dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_aware_dbl = as.numeric(htn_aware)-1)

summary(dhs_nomiss$htn_aware)

##treated htn as subset of htns


dhs_nomiss <- mutate(dhs_nomiss,
                     htn_treated = ifelse(hypt_med==1 & ex_htn_broad_ind==1, 1, 0))
#dhs_nomiss[which(is.na(dhs_nomiss$htn_treated)==T), "htn_treated"]<-0

dhs_nomiss$htn_treated <- as.factor(dhs_nomiss$htn_treated)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_treated_dbl = as.numeric(htn_treated)-1)

summary(dhs_nomiss$htn_treated)

##controlled htn as subset of  htns

dhs_nomiss <- mutate(dhs_nomiss,
                     htn_controlled = ifelse(hypt_med==1 & ex_htn_narrow_ind==0 & ex_htn_broad_ind==1, 1, 0))

dhs_nomiss$htn_controlled <- as.factor(dhs_nomiss$htn_controlled)

dhs_nomiss <- mutate(dhs_nomiss,
                     
                     htn_controlled_dbl = as.numeric(htn_controlled)-1)

summary(dhs_nomiss$htn_controlled)


################## Zones as per: https://en.wikipedia.org/wiki/Administrative_divisions_of_India
dhs_nomiss <- mutate(dhs_nomiss, 
                     # Nothern
                     zone = as.factor(ifelse(ex_state_ind=="Chandigarh" | ex_state_ind=="NCT of Delhi" | ex_state_ind=="Haryana" | ex_state_ind=="Himachal Pradesh" | ex_state_ind=="Punjab" | ex_state_ind=="Rajasthan" | ex_state_ind=="Jammu and Kashmir", "North",
                                             # Northeastern
                                             ifelse(ex_state_ind=="Assam" | ex_state_ind=="Arunachal Pradesh" | ex_state_ind=="Manipur" | ex_state_ind=="Meghalaya" | ex_state_ind=="Mizoram" | ex_state_ind=="Nagaland" | ex_state_ind=="Sikkim" | ex_state_ind=="Tripura", "Northeast",
                                                    # Central
                                                    ifelse(ex_state_ind=="Chhattisgarh" | ex_state_ind=="Madhya Pradesh" | ex_state_ind=="Uttarakhand" | ex_state_ind== "Uttar Pradesh", "Central",
                                                           # Eastern
                                                           ifelse(ex_state_ind=="Bihar" | ex_state_ind=="Jharkhand" | ex_state_ind=="Odisha" | ex_state_ind=="West Bengal", "East",
                                                                  # Western
                                                                  ifelse(ex_state_ind=="Daman and Diu" | ex_state_ind=="Goa" | ex_state_ind=="Maharashtra" | ex_state_ind=="Gujarat", "West",
                                                                         # Southern
                                                                         ifelse(ex_state_ind=="Andaman and Nicobar" | ex_state_ind=="Andhra Pradesh" | ex_state_ind=="Karnataka" | ex_state_ind=="Kerala" | ex_state_ind=="Puducherry" | ex_state_ind=="Tamil Nadu" | ex_state_ind=="Telangana", "South", NA))))))))





####### Adding state labels
dhs_nomiss <- mutate(dhs_nomiss, state_lab = fct_recode(ex_state_ind, 
                                                        "HP" = "Himachal Pradesh",
                                                        "PB" = "Punjab",
                                                        "CH" = "Chandigarh",
                                                        "HR" = "Haryana",
                                                        "DL" = "Delhi",
                                                        "SK" = "Sikkim",
                                                        "DD" = "Daman and Diu",
                                                        "AR" = "Arunachal Pradesh",
                                                        "NL" = "Nagaland",
                                                        "MN" = "Manipur",
                                                        "MZ" = "Mizoram",
                                                        "TR" = "Tripura",
                                                        "ML" = "Meghalaya",
                                                        "WB" = "West Bengal",
                                                        "MH" = "Maharashtra",
                                                        "AP" = "Andhra Pradesh",
                                                        "KA" = "Karnataka",
                                                        "GA" = "Goa",
                                                        "KL" = "Kerala",
                                                        "PY" = "Puducherry",
                                                        "TN" = "Tamil Nadu",
                                                        "AN" = "Andaman and Nicobar Islands",
                                                        "TS" = "Telangana",
                                                        "UK" = "Uttarakhand",
                                                        "RJ" = "Rajasthan",
                                                        "UP" = "Uttar Pradesh",
                                                        "BR" = "Bihar",
                                                        "AS" = "Assam",
                                                        "JK" = "Jammu and Kashmir",
                                                        "GJ" = "Gujarat",
                                                        "JH" = "Jharkhand",
                                                        "OD" = "Odisha",
                                                        "CT" = "Chhattisgarh", 
                                                        "MP" = "Madhya Pradesh"))



dhs_nomiss <- mutate(dhs_nomiss, 
                     urban_dbl = as.numeric(urban))

#install.packages("spatstat")

dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Puducherry") 
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Daman and Diu")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Delhi")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Dadra and Nagar Haveli")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Andaman and Nicobar Islands")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Lakshadweep")
dhs_nomiss <- dplyr::filter(dhs_nomiss, ex_state_ind != "Chandigarh")

library(spatstat)
statemean.dat <- dhs_nomiss %>%
  group_by(d_id) %>% 
  mutate(prop_urban = weighted.mean(urban_dbl, p_wt_new, na.rm=TRUE)) %>% 
  mutate(htn = weighted.mean(ex_htn_broad_ind_dbl, p_wt_new, na.rm=TRUE)*100,
         screenedmean = ((weighted.mean(htn_screened_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         awaremean = ((weighted.mean(htn_aware_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100, 
         treatedmean = ((weighted.mean(htn_treated_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100,
         controlledmean = ((weighted.mean(htn_controlled_dbl, p_wt_new, na.rm=TRUE)*100)/htn)*100) %>%
  filter(row_number()==1) %>%
  ungroup() %>% 
  dplyr::select(d_id, zone, htn, screenedmean, awaremean, treatedmean, controlledmean,  prop_urban)

write.csv(statemean.dat, "Colored reg fig estimates htn.csv")

#####Screened 
stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=screenedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=screenedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  # geom_text_repel(aes(y=htn, x=screenedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=screenedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Screened, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30, 35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateawarefig


#####Aware

stateawarefig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=awaremean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=awaremean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  #geom_text_repel(aes(y=htn, x=awaremean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=awaremean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Aware, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30,35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateawarefig


#######Treated


stateTreatedfig <- statemean.dat %>% 
  
  ggplot(aes(y=htn, x=treatedmean)) +
  geom_smooth(method='glm', se= FALSE, color="black") +
  geom_jitter(aes(y=htn, x=treatedmean, color=zone, shape=zone), size=2.5) +
  #geom_boxplot(mapping=aes(y=diab, x=treatedmean, label= state_lab group=as.factor(treatedmean)), outlier.shape = NA, alpha=0.8) +
  #geom_text_repel(aes(y=htn, x=treatedmean, label = state_lab)) +
  #geom_label_repel (aes(y=htn, x=treatedmean,label=state_lab)) +
  theme_classic() + 
  labs(x = "Treated, in %",
       y = " Hypertension prevalence, in %",
       fill="") +
  theme(axis.text=element_text(size=20),
        axis.title=element_text(size=22, face="bold"),
        legend.text=element_text(size=20),
        legend.title = element_blank(),
        #legend.position="bottom",
        axis.title.x = element_text(margin = margin(t = 20)),
        axis.title.y = element_text(margin = margin(r = 20)),
        strip.text.x = element_text(size=22, face="bold"),
        strip.background = element_blank(),
        panel.spacing = unit(2, "lines")) + 
  scale_color_brewer(palette="Dark2") +
  scale_y_continuous(breaks = c(0, 5, 10,15, 20, 25,30, 35), limits=c(0, 35)) +
  scale_x_continuous(breaks = c(20, 40, 60, 80,100), limits=c(0, 100)) +
  coord_fixed(100/35, expand=F)
stateTreatedfig





####p-values

summary(lm(formula = htn ~ screenedmean, data = statemean.dat))
summary(lm(formula = htn ~ awaremean, data = statemean.dat))
summary(lm(formula = htn ~ treatedmean, data = statemean.dat))







```

